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

Christopher Barker Chris.Barker at noaa.gov
Wed Feb 22 12:27:11 EST 2006


Sven Schreiber wrote:
> - If I have >1 variable then everything is fine (provided I use your
> advice of slicing instead of indexing afterwards) and the variables are
> in the _columns_ of the 2d-array.
> - But if there's just one data _column_ in the file, then pylab/numpy
> gives me a 1d-array that sometimes works as a _row_ (and as you noted,
> sometimes not), but never works as a column.
> 
> Imho that's bad, because as a consequence I must use overhead code to
> distinguish between these cases.

I'd do that on load. You must have a way of knowing how many variables 
you're loading, so when it is one you can add this line:

a.shape = (1,-1)

and then proceed the same way after that.

-chris




-- 
Christopher Barker, Ph.D.
Oceanographer
                                     		
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