I have to switch between MATLAB and NumPy (Python 3.x) . What always causes problems for me, is the way vectors are used in NumPy. In MATLAB a vector is more or less nothing else than a 1xn or nx1 matrix. To provide an example:
b=np.array([0,2])
is a (2,) array and in fact it is not useful for any matrix operation because in that case I have to do something like b.reshape(2,1)
before. At almost any time I have to reshape the vectors/arrays returned by functions. Can someone tell me why NumPy arrays are not treated like column or row vectors by default? And because I have got to do it so often … is reshape the best way to do it?
b[:, None]
if I need a (n,1) array.numpy
usually treats a (n,) array as (1,n), that is it adds new dims at the start if needed. Matlab expends dims at the other end. – hpaulj