Convert numpy ndarray to matlab mlarray in python
古いコメントを表示
mlarray to ndarray: np.asarray(x._data, dtype=dtype)
but inversely, ndarray to mlarray: matlab.double(x.tolist()), which is extremely slow, is there a more efficient way to do this? Thank u for answering.
採用された回答
その他の回答 (3 件)
Al Danial
2022 年 4 月 21 日
Which version of MATLAB? 2020a and newer (I don't have easy access to older versions) should just be able to do
>> mx = double(x);
without a conversion to a list.
2 件のコメント
Gan Lee
2022 年 4 月 24 日
Christopher Wunder
2022 年 8 月 23 日
This is not possible for me either.
The function _is_initializer in matlab._internal.mlarray_utils.py checks for the input to be of type collections.abc.Sequence and a numpy.ndarray fails to be of such a type. The only way (without altering the package) is to convert the array beforehand or pass any kind of Sequence to it instead of an array.
Al Danial
2022 年 4 月 24 日
0 投票
Now I'm curious what is in your variable x. Can you make a small version of this data, write it to a .mat file, then attach the .mat file?
カテゴリ
ヘルプ センター および File Exchange で Call Python from MATLAB についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!