[Numpy-discussion] mixing arrays and matrices: squeeze yes, flattened no?

Christopher Barker Chris.Barker at noaa.gov
Tue Feb 21 12:49:02 CST 2006

Travis Oliphant wrote:

> You can mix arrays and matrices just fine if you remember that 1d arrays 
> are equivalent to row-vectors.

and you can easily get a column vector out of an array, if you remember 
that you want to keep it 2-d. i.e. use a slice rather than an index:

 >>> import numpy as N
 >>> a = N.ones((5,10))
 >>> a[:,1].shape # an index: it reduces the rank
 >>> a[:,1:2].shape # a slice: it keeps the rank
(5, 1)


Christopher Barker, Ph.D.
NOAA/OR&R/HAZMAT         (206) 526-6959   voice
7600 Sand Point Way NE   (206) 526-6329   fax
Seattle, WA  98115       (206) 526-6317   main reception

Chris.Barker at noaa.gov

More information about the Numpy-discussion mailing list