[SciPy-dev] matrix and ravel()

Robert Kern rkern at ucsd.edu
Tue Oct 11 22:11:58 CDT 2005

Travis Oliphant wrote:
> Robert Kern wrote:
>>In [1]: A = array([[1,2],[3,4]])
>>In [2]: B = mat(A)
>>In [3]: ravel(A)
>>Out[3]: array([1, 2, 3, 4])
>>In [4]: ravel(B)
>>Out[4]: matrix([[1, 2, 3, 4]])
>>This appears to be a side effect of the new __array_finalize__ magic.
>>I'm not sure that it's desirable. I'm also not sure that it's desirable
>>to change it.
> 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).

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.

Robert Kern
rkern at ucsd.edu

"In the fields of hell where the grass grows high
 Are the graves of dreams allowed to die."
  -- Richard Harter

More information about the Scipy-dev mailing list