Difference between array( [1,0,1] ) and array( [ [1,0,1] ] )

edmondo.giovannozzi at gmail.com edmondo.giovannozzi at gmail.com
Fri Jun 21 06:54:57 EDT 2019


Keep also in mind that numpy is quite different from Matlab.
In Matlab every vaiable is a matrix of at least 2 dimensions.

This is not the case of numpy (and is not the case in Fortran too).
every array can have a different number of dimensions. The transposition of an array with just 1 dimension is not really meaningful.
On the other hand most of the time is not needed.
For example le have a matrix:
a = np.array([[1,2],[1,1]])
and an array:
b = np.array([0.1,0.2])
You can left multiply or right multiply it to this matrix without any need to transpose it  (as you have to do in Matlab):
a @ b
array([0.5,0.3])
b @ a
array([0.3,0.4])
Cheers,


 

 



More information about the Python-list mailing list