主要内容

本页采用了机器翻译。点击此处可查看英文原文。

MATLAB Production ServerPython 之间传递数据

MATLABPython 传递数据

当您将数据从 MATLAB® 传递给 Python® 时,无论是直接传递数据还是将数据作为 MATLAB 中 Python 函数的输出传递,MATLAB Production Server™ 都会将数据转换为等效的 Python 数据类型。

MATLAB 输出参量类型
(除非另有说明,否则均为标量)

生成的 Python 数据类型

数值数组

matlab 数值数组对象
请参阅MATLAB 数组作为 Python 变量 (MATLAB)

double
single

float

复数(任何数值类型)

complex

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

int

NaN

float('nan')

Inf

float('inf')

logical

bool

char 数组(1×NN×1)

str

string

str

string 数组(1×NN×1)

strlist

struct

dict

元胞数组(1×NN×1)

list

datetime

MATLAB Production Server 不支持这种转换。

duration

MATLAB Production Server 不支持这种转换。

datetime 数组

MATLAB Production Server 不支持这种转换。

duration 数组

MATLAB Production Server 不支持这种转换。

table
timetable

MATLAB Production Server 不支持这种转换。

dictionary

MATLAB Production Server 不支持这种转换。

MATLAB 句柄对象(例如 containers.Map 类型)

MATLAB Production Server 不支持这种转换。

MATLAB 值对象(例如 categorical 类型)

MATLAB Production Server 不支持这种转换。

不支持的 MATLAB 数据类型

除了表中注明的例外情况外,MATLAB 不会将以下 MATLAB 数据类型转换为 Python 数据类型:

  • char 数组 (M×N)

  • string 数组 (M×N)

  • 元胞数组 (M×N)

  • 稀疏数组

  • struct 数组

  • 非 MATLAB 生成的对象(例如 Java® 对象)

  • 函数句柄

PythonMATLAB 传递数据

当您将数据从 Python 传递给 MATLAB 时,无论是直接传递还是将数据作为 MATLAB 中 Python 函数的输入参量进行传递,MATLAB Production Server 都会将数据转换为等效的 MATLAB 数据类型。

Python 数据类型

生成的 MATLAB 数据类型
(除非另有说明,否则均为标量)

matlab 数值数组对象

数值数组
请参阅matlab Python 模块

支持缓冲区协议的 Python 对象,例如 memoryviewarray.array 或 NumPy ndarray

数值数组

float

double

complex

复数 double

int

int64

float('nan')

NaN

float('inf')

Inf

bool

logical

str

char

bytearray

uint8 数组

bytes

uint8 数组

list

cell 数组

set

cell 数组

tuple

cell 数组

dict

struct
dict 键必须符合特定规范。请参阅在 MATLAB 中使用 Python 字典 (MATLAB)

datetime.datetime
numpy.datetime64 标量

MATLAB Production Server 不支持这种转换。

datetime.timedelta
numpy.timedelta64 标量

MATLAB Production Server 不支持这种转换。

numpy.datetime64 数组

MATLAB Production Server 不支持这种转换。

numpy.timedelta64 数组

MATLAB Production Server 不支持这种转换。

pandas.DataFrame

MATLAB Production Server 不支持这种转换。

具有 datetime 列的 pandas.DataFrame

MATLAB Production Server 不支持这种转换。

matlab.dictionary

MATLAB Production Server 不支持这种转换。

dict 之外的支持映射协议的 Python 对象(例如 collections.OrderedDict

MATLAB Production Server 不支持这种转换。

不支持的 Python 数据类型

除了表中注明的例外情况外,MATLAB 不会将以下 Python 数据类型转换为 MATLAB 数据类型:

  • Python 类 (module.type) 对象

  • None 对象

另请参阅

主题