目录
处理从 Python 返回的数据
Python 类型到 MATLAB 类型的自动映射
显式类型转换
处理从 Python 返回的数据
Python 类型到 MATLAB 类型的自动映射
下表显示 MATLAB® 如何将从 Python® 返回的数据转换为 MATLAB 类型。
Python 返回类型,如 Python 中所显示 | 生成的 MATLAB 类型 - 标量 |
---|
bool | logical |
int (仅限版本 2.7)。对于 Python 版本 3.x int ,您必须显式转换。 | int64 |
float | double |
complex | 复数 double |
所有其他 Python 类型 - type | Python 对象 - py .type |
显式类型转换
MATLAB 提供下列函数,用于手动将 Python 数据类型转换为 MATLAB 类型。
Python 返回类型或协议,如在 MATLAB 中所显示 | MATLAB 转换函数 |
---|
py.str (版本 2.7) | string
char
uint8 |
py.str (版本 3.x) | string
char |
py.unicode | string
char |
使用 __str__ 方法的对象 | char |
py.bytes | uint8 |
py.int | double 或
int64 |
py.long | double 或
int64 |
py.array.array [a] | numeric
double
single
int8
uint8
int16
uint16
int32
uint32
int64
uint64 |
序列协议;例如,py.list 和 py.tuple | cell |
映射协议;例如,py.dict | struct |
[a] You can convert py.array.array of any format to the MATLAB type you want. |