[Numpy-discussion] a.squeeze() for 1d and 0d arrays

Ed Schofield schofield at ftw.at
Sat May 20 04:51:01 EDT 2006


Hi all,

I've discovered a bug in my SciPy code for sparse matrix slicing that
was caused by the following behaviour of squeeze():

>>> a = array([3])    # array of shape (1,)
>>> type(a.squeeze())
<type 'int32scalar'>

That is, squeezing a 1-dim array returns an array scalar.  Could we
change this to return a 0-dim array instead?

Another related question is this:

>>> b = array(3)    # 0-dim array
>>> type(a.squeeze())
<type 'int32scalar'>

I find this behaviour surprising too; the docstring claims that squeeze
eliminates any length-1 dimensions, but a 0-dimensional array has shape
(), without any length-1 dimensions.  So shouldn't squeeze() leave
0-dimensional arrays alone?

-- Ed





More information about the NumPy-Discussion mailing list