如何将numpy数组转换成Matlab矩阵?

2024-04-23 19:10:54 发布

您现在位置:Python中文网/ 问答频道 /正文

我有测试Python.py公司名称:

import numpy as np
def numpyTest():
    print("Testing numpy...")
    x = np.array([1,2,3])
    return x

我有测试。m:

^{pr2}$

当我运行测试时,我得到:

正在测试numpy。。。在

value = 

  Python ndarray with properties:

           T: [1×1 py.numpy.ndarray]
        base: [1×1 py.NoneType]
      ctypes: [1×1 py.numpy.core._internal._ctypes]
        data: [1×24 py.buffer]
       dtype: [1×1 py.numpy.dtype]
       flags: [1×1 py.numpy.flagsobj]
        flat: [1×1 py.numpy.flatiter]
        imag: [1×1 py.numpy.ndarray]
    itemsize: 8
      nbytes: 24
        ndim: 1
        real: [1×1 py.numpy.ndarray]
       shape: [1×1 py.tuple]
        size: 3
     strides: [1×1 py.tuple]

    [1 2 3]

如何将python numpy数组转换为matlab矩阵?在


Tags: pyimportnumpy名称defasnp公司
1条回答
网友
1楼 · 发布于 2024-04-23 19:10:54

我们必须在这里进行一些转换:

clear; clc;

value = py.testPython.numpyTest();% ndarray
pyList = value.tolist(); % ndarray -> pylist
result = cellfun(@double,cell(pyList)) %pylist-> cell array -> double array

另一个选择是通过文件传输数据,但我不喜欢。在

以及有关Python列表转换的Matlab文档的链接:

https://www.mathworks.com/help/matlab/matlab_external/use-python-list-of-numeric-types-in-matlab.html

相关问题 更多 >