什么是:在matlab语法中的含义,以及如何将其翻译为python



我正在尝试将一些matlab代码改编成python,具体行是这个

0:1/2047:1

与上面的行等价的python是什么?我将其解释为

a = np.arange(1,2048,1)
b = 1/a[::-1]

但我不确定这是否正确。

在Octave会话中(自由源(

>> 1:5
ans =
1   2   3   4   5
>> 1:.5:5
ans =
Columns 1 through 7:
1.0000    1.5000    2.0000    2.5000    3.0000    3.5000    4.0000
Columns 8 and 9:
4.5000    5.0000

显然,这是numpynp.arange的变体。

还有一个更接近numpy版本的linspace(MATLAB是第一个(:

>> linspace(1,5,10)
ans =
Columns 1 through 8:
1.0000   1.4444   1.8889   2.3333   2.7778   3.2222   3.6667   4.1111
Columns 9 and 10:
4.5556   5.0000

最新更新