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

Sven Schreiber svetosch at gmx.net
Wed Feb 22 06:48:09 EST 2006


Christopher Barker schrieb:
> Sven Schreiber wrote:

>> I guess I'd rather follow the advice and just remember to treat 1d as
>> a row.
> 
> Except that it's not, universally. For instance, it won't transpose:
> 


> 
> It's very helpful to remember that indexing reduces rank, and slicing
> keeps the rank the same. It will serve you well to use that in the
> future anyway.
> 

Anyway, the problem is really about interaction with pylab/matplotlib
(so slightly OT here, sorry); when getting data from a text file with
pylab.load you can't be sure if the result is 1d or 2d.

This means that:

- 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.

To me it seems more like pylab's bug instead of numpy's, so please
excuse this OT twist, but since there seems to be overlap between the
pylab/matplotlib and numpy folks, maybe it's not so bad.

Thanks for your patience and helpful input,
Sven





More information about the NumPy-Discussion mailing list