[SciPy-dev] matrix and ravel()
oliphant at ee.byu.edu
Tue Oct 11 21:49:58 CDT 2005
Robert Kern wrote:
>In : A = array([[1,2],[3,4]])
>In : B = mat(A)
>In : ravel(A)
>Out: array([1, 2, 3, 4])
>In : ravel(B)
>Out: 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
It does bring up an issue, though, and may require some re-thinking.
asarray(a) will return a if a is any sub-class of a (big)ndarray.
asarray(a) will return a matrix if a is a matrix.
a = asarray(a)
will do matrix multiplication if a matrix is passed in,
but element-by-element multiplication if another array is passed in.
asndarray(a) will always return a base-class array (even 0-d arrays).
One option, I suppose is to change the meaning of asarray to asndarray,
(thus destroying the ability for matrices to perservere through many
operations) --- and introduce another function like asanyarray or
something to mean any sub-class is O.K. too.
More information about the Scipy-dev