[Numpy-discussion] multiply a lign matrix with a column matrix should return a scalar( matlab yes, numpy no)!!!

David Cournapeau david@silveregg.co...
Wed Feb 3 02:20:23 CST 2010


laurent.feron@free.fr wrote:
> Hello,
> 
> if i multiply two matrix, one with a unique line and the second one with a unique column, i should have a scalar:
> 
>>>> line
> matrix([[1, 3, 1]])
>>>> col
> matrix([[2],
>         [2],
>         [2]])
>>>> line*col
> matrix([[10]])
> 
> Matlab give me a scalar, Numpy does not...

Matlab does not have the concept of scalar: everything is a matrix 
(size(1) returns (1, 1) in matlab). NumPy matrix objects are more or 
less the same: every operation between two matrices return a matrix.

Although natural coming from a matlab background, I would advise against 
using matrices because they look more familiar. I did the same mistake 
when I started using NumPy, and getting used to NumPy arrays took me 
more time.

cheers,

David



More information about the NumPy-Discussion mailing list