Getting error while importing numpy in MATLAB

I have installed a MATLAB supported version python 3.5. I have also installed numpy library and it can be imported in python compiler. But when I try a numpy code in MATLAB it gives error like this
x=py.numpy.linspace(0,10,101);
it gives following error which I am unable to understand.
Error using function_base>linspace (line 121)
Python Error: TypeError: object of type <class 'float'> cannot be safely interpreted as an integer.
Error in <__array_function__ internals>>linspace (line 6)
I need help to resolve this issue as I need to use python comands in MATLAB.

 採用された回答

Ameer Hamza
Ameer Hamza 2020 年 10 月 22 日

0 投票

This issue happens in the latest versions of numpy. Following will work
x = py.numpy.linspace(0, 10, py.numpy.int(101))

6 件のコメント

Sajid Sarwar
Sajid Sarwar 2020 年 10 月 23 日
What I have to do if I need to change whole project from python to MATLAB code?
Ameer Hamza
Ameer Hamza 2020 年 10 月 23 日
You need to write the MATLAB code manually. I don't think there is an automatic tool to do this.
Sajid Sarwar
Sajid Sarwar 2020 年 10 月 23 日
x = py.numpy.linspace(0, 10, py.numpy.int(101))
Above command gives output as ndarray. How can I change it into double. y=double(x) is not working.
Error using double
Conversion to double from py.numpy.ndarray is not possible.
Ameer Hamza
Ameer Hamza 2020 年 10 月 24 日
編集済み: Ameer Hamza 2020 年 10 月 24 日
Which python version are you using? Maybe try this
x = py.numpy.linspace(0, 10, py.numpy.int(101))
y = x.double
Sajid Sarwar
Sajid Sarwar 2020 年 10 月 24 日
y=x.double; is not working. I am using python 3.5
y=x.double gives following error,
No appropriate method, property, or field 'double' for class 'py.numpy.ndarray'.
Ameer Hamza
Ameer Hamza 2020 年 10 月 25 日
i am not getting these errors. I am using python 3.8 with numpy 1.18.5.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

質問済み:

2020 年 10 月 22 日

コメント済み:

2020 年 10 月 25 日

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by