Main Content

Pass Data Between MATLAB Production Server and Python

Pass Data from MATLAB to Python

When you pass data from MATLAB® to Python®, either directly or as output from a MATLAB function in Python, MATLAB Production Server™ converts the data into the equivalent Python data types.

MATLAB Output Argument Type
(scalar unless otherwise noted)

Resulting Python Data Type

Numeric array

matlab numeric array object
See MATLAB Arrays as Python Variables (MATLAB).

double
single

float

Complex (any numeric type)

complex

int8, int16, int32, int64
uint8, uint16, uint32, uint64

int

NaN

float('nan')

Inf

float('inf')

logical

bool

char array (1-by-N or N-by-1)

str

string

str

string array (1-by-N or N-by-1)

list of str

struct

dict

cell array (1-by-N or N-by-1)

list

datetime

This conversion is not supported for MATLAB Production Server.

duration

This conversion is not supported for MATLAB Production Server.

datetime array

This conversion is not supported for MATLAB Production Server.

duration array

This conversion is not supported for MATLAB Production Server.

table
timetable

This conversion is not supported for MATLAB Production Server.

dictionary

This conversion is not supported for MATLAB Production Server.

MATLAB handle object (such as the containers.Map type)

This conversion is not supported for MATLAB Production Server.

MATLAB value object (such as the categorical type)

This conversion is not supported for MATLAB Production Server.

Unsupported MATLAB Data Types

Along with the exceptions noted in the table, MATLAB does not convert these MATLAB data types to Python data types:

  • char array (M-by-N)

  • string array (M-by-N)

  • cell array (M-by-N)

  • Sparse array

  • struct array

  • Objects not produced by MATLAB (such as Java® objects)

  • Function handle

Pass Data from Python to MATLAB

When you pass data from Python to MATLAB, either directly or as input arguments to a MATLAB function in Python, MATLAB Production Server converts the data into the equivalent MATLAB data types.

Python Data Type

Resulting MATLAB Data Type
(scalar unless otherwise noted)

matlab numeric array object

Numeric array
See matlab Python Module.

Python objects that support the buffer protocol, such as memoryview, array.array, or NumPy ndarray

Numeric array

float

double

complex

Complex double

int

int64

float('nan')

NaN

float('inf')

Inf

bool

logical

str

char

bytearray

uint8 array

bytes

uint8 array

list

cell array

set

cell array

tuple

cell array

dict

struct
dict keys must meet certain specifications. See Use Python Dictionaries in MATLAB (MATLAB).

datetime.datetime
numpy.datetime64 scalar

This conversion is not supported for MATLAB Production Server.

datetime.timedelta
numpy.timedelta64 scalar

This conversion is not supported for MATLAB Production Server.

numpy.datetime64 array

This conversion is not supported for MATLAB Production Server.

numpy.timedelta64 array

This conversion is not supported for MATLAB Production Server.

pandas.DataFrame

This conversion is not supported for MATLAB Production Server.

pandas.DataFrame with datetime column

This conversion is not supported for MATLAB Production Server.

matlab.dictionary

This conversion is not supported for MATLAB Production Server.

Python objects other than dict that support the mapping protocol (such as collections.OrderedDict)

This conversion is not supported for MATLAB Production Server.

Unsupported Python Data Types

Along with the exceptions noted in the table, MATLAB does not convert these Python data types to MATLAB data types:

  • Python class (module.type) objects

  • None object

See Also

Topics