Differences Between Arrays and Matrices in Numpy

Colin J. Williams cjw at ncf.ca
Wed Jul 29 19:27:41 EDT 2009


Robert Kern wrote:
> On 2009-07-29 15:23, Nanime Puloski wrote:
>> What are some differences between arrays and matrices using the Numpy
>> library? When would I want to use arrays instead of matrices and vice
>> versa?
> 
> You will want to ask numpy questions on the numpy mailing list:
> 
>   http://www.scipy.org/Mailing_Lists
> 
> An overview of how the matrix subclass differs from ndarray, see the 
> documentation:
> 
>   
> http://docs.scipy.org/doc/numpy/reference/arrays.classes.html#matrix-objects 
> 
> 
> Basically, I suggest that you just use regular arrays always. There is a 
> syntactical convenience to matrix objects, but it does cause 
> incompatibilities with the majority of code that is written for regular 
> arrays. The convenience is usually not worth the cost.
> 

Numpy's arrays can have any dimensionality, whereas 
matrices[http://en.wikipedia.org/wiki/Matrix_%28mathematics%29], typically 
have two.  A single column can represent a vector or a single row can 
represent a transposed vector.

Does the additional cost arise because the commonly used procedures are 
accessed through numpy's array?

Colin W.




More information about the Python-list mailing list