[SciPy-user] asanyarray

Robert Kern robert.kern@gmail....
Fri Feb 2 01:56:39 CST 2007


Nils Wagner wrote:
> Hi,
> 
> I am confused about the behaviour of asanyarray
> 
> Python 2.4.1 (#1, Oct 13 2006, 16:51:58)
> [GCC 4.0.2 20050901 (prerelease) (SUSE Linux)] on linux2
> Type "help", "copyright", "credits" or "license" for more information.
>>>> from scipy import *
>>>> A = io.mmread('mhd416a.mtx.gz')
>>>> A
> <416x416 sparse matrix of type '<type 'numpy.float64'>'
>         with 8562 stored elements in COOrdinate format>
>>>> shape(A)
> (416, 416)
>>>> A=asanyarray(A)
>>>> A
> array(<416x416 sparse matrix of type '<type 'numpy.float64'>'
>         with 8562 stored elements in COOrdinate format>, dtype=object)
>>>> shape(A)
> ()
>  
> Help on function asanyarray in module numpy.core.numeric:
> 
> asanyarray(a, dtype=None, order=None)
>     Returns a as an array, but will pass subclasses through.
> 
> Why is the shape altered by asanyarray ?

Because sparse arrays are not instances of a subclass of numpy.ndarray. Thus,
asanyarray(A) is interpreted as a 0-dim object array.

-- 
Robert Kern

"I have come to believe that the whole world is an enigma, a harmless enigma
 that is made terrible by our own mad attempt to interpret it as though it had
 an underlying truth."
  -- Umberto Eco


More information about the SciPy-user mailing list