MATLAB代码生成一个(1,n)大小的矩阵,该矩阵被转换为(n,1)
>> 2:5
ans =
2 3 4 5
>> (2:5)'
ans =
2
3
4
5
MATLAB矩阵总是2d(或更高)。
numpy
阵列可以是1d甚至0d。
https://numpy.org/doc/stable/user/numpy-for-matlab-users.html
在里面
努比
:
arange
生成1d阵列:
In [165]: np.arange(2,5)
Out[165]: array([2, 3, 4])
In [166]: _.shape
Out[166]: (3,)
向数组中添加尾随维度的方法有多种:
In [167]: np.arange(2,5)[:,None]
Out[167]:
array([[2],
[3],
[4]])
In [168]: np.arange(2,5).reshape(3,1)
Out[168]:
array([[2],
[3],
[4]])
努比
有一个转置,但它在一维数组中的行为并不是人们对二维数组的期望。它实际上比MATLAB更强大、更通用
'
.