Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/matlab/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
MATLAB类型转换函数的等价Python函数_Python_Matlab_Casting - Fatal编程技术网

MATLAB类型转换函数的等价Python函数

MATLAB类型转换函数的等价Python函数,python,matlab,casting,Python,Matlab,Casting,我有一个数组数据,大小[1,34] 使用MATLAB将此大小数组转换为8位无符号整数数组,结果如下: >> typecast(size(Data), 'uint8') >> 0 0 0 0 0 0 240 63 0 0 0 0 0 0 65 64 我在Python中尝试了以下内容: >> x = np.array([1,34],dtype = np.int64) >&g

我有一个数组
数据
,大小
[1,34]

使用MATLAB将此大小数组转换为8位无符号整数数组,结果如下:

>> typecast(size(Data), 'uint8') 
>> 0    0    0    0    0    0  240   63    0    0    0    0    0    0   65   64

我在Python中尝试了以下内容:

>> x = np.array([1,34],dtype = np.int64)
>> x.view(np.uint8)
>> array([ 1,  0,  0,  0,  0,  0,  0,  0, 34,  0,  0,  0,  0,  0,  0,  0],
      dtype=uint8)

这些显然是不同的。我怎样才能得到相同的结果,我也非常欣赏MATLAB结果背后的推理

我也参考了答案。

MATLAB代码
大小(数据)
返回双精度浮点数组,这是MATLAB的默认类型

Python中的等效项应为:

x=np.array([1,34],dtype=np.double)
x、 视图(np.uint8)