Convert matlab zeros function to Python equivalent
古いコメントを表示
Hi Could you pleas elet me know what would be a similar conversion of matlab zeros to np.zeros for datatype. I am getting an error while doing this.
Matlab code:
Shifts = zeros(length(Filters)-1,1,'int16');
Python code:
Shifts = np.zeros(len(Filters)-1,1,dtype = np.int16)
6 件のコメント
Raghunandan V
2019 年 5 月 28 日
Hey,
I tried the same. It works!
Prb
2019 年 5 月 28 日
Rik
2019 年 5 月 28 日
You should post this to a python forum.
Murugan C
2019 年 5 月 28 日
hi,
I think we have to create zeros as like below syntax.
Shifts = np.zeros(len(Filters)-1,dtype = np.int16)
Prb
2019 年 5 月 29 日
Murugan C
2019 年 5 月 29 日
What is size of the Filters. If lenght of "Filters" is empty or zeros, then only you will get negative dimensitons.
>>> import numpy
>>> Filters = [ ]
>>> Shifts = numpy.zeros(len(Filters)-1,dtype = numpy.int16)
Traceback (most recent call last):
File "<pyshell#20>", line 1, in <module>
Shifts = numpy.zeros(len(Filters)-1,dtype = numpy.int16)
ValueError: negative dimensions are not allowed
>>>
%%
>>> Filters = [5, 6, 4, 5,6]
>>> Shifts = numpy.zeros(len(Filters)-1,dtype = numpy.int16)
>>> Shifts
array([0, 0, 0, 0], dtype=int16)
採用された回答
その他の回答 (0 件)
カテゴリ
ヘルプ センター および 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!