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

Sven Schreiber svetosch at gmx.net
Tue Feb 21 15:49:02 CST 2006


Travis Oliphant schrieb:
> Sven Schreiber wrote:

> 
>> Next, I try to workaround by b.squeeze(). That seems to work, but why is
>> b.squeeze().shape == (1, 112) instead of (112,)?
>>  
>>
> Again the same reason as before.  A matrix is returned from b.squeeze()
> and there are no 1-d matrices.   Thus, you get a row-vector.   Use .T if
> you want a column vector.

Well if squeeze can't really squeeze matrix-vectors (doing a de-facto
transpose instead), wouldn't it make more sense to disable the squeeze
method for matrices altogether?

> 
>> Then I thought maybe b.flattened() does the job, but then I get an error
>> (matrix has no attr flattened). Again, I'm baffled.
>>  
>>
> The correct spelling is b.flatten()

Ok, but I copied .flattened() from p. 48 of your book, must be a typo then.


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

Btw, did the recent numpy release change anything in terms of preserving
matrix types when passing to decompositions etc? I checked the release
notes but maybe they're just not verbose enough.
-Sven






More information about the Numpy-discussion mailing list