[SciPy-dev] matrix and ravel()

Alan G Isaac aisaac at american.edu
Wed Oct 12 08:14:22 CDT 2005


> Travis Oliphant wrote: 
>> Not really a side-effect.  An intended feature.   Matrices are supposed 
>> to be matrices (i.e. 2-d arrays).  They cannot be 1-d arrays no matter 
>> how hard you try....  If you want to ravel a matrix and get a 1-d array 
>> out,  you are not using matrices right....  Use a 1-d array (i.e. the .A 
>> attribute). 

On Tue, 11 Oct 2005, Robert Kern apparently wrote: 
> It's kind of an Immovable Object meets Irresistable Force deal. I expect 
> ravel() to always give me a 1-d array, and I also expect matrix object 
> to always by 2-d. I'm willing to concede the fact that all of my desires 
> are mutually contradictory in this regard. 


User comments:
1. Better support for matrices is very welcome; I use them 
   a lot.
2. I expect ravel to return a 1-d array, not a matrix.  My 
   background is a matrix programming language (GAUSS from 
   before its N-dimensional array support), and yet the 
   behavior of ravel never surprised me.
3. I expect a row and column vectorization functions (named 
   e.g., vecr and vecc) to do row and column vectorization.  
   I do not have a strong opinion on whether what is really 
   wanted is a vec function that takes an axis argument, 
   although this is probably right.  In particular, both row 
   and column vectorization of matrices is common, and this 
   is just a choice of axis.

So as a user I suggest that this new functionality of ravel 
creates unwanted surprises, in addition to breaking past 
code, and as long as vec is available, will imply no missing 
functionality.

The same goes double for asarray: it will be a really 
unwanted surprise if it does not return an array.

fwiw,
Alan Isaac





More information about the Scipy-dev mailing list