[SciPy-user] scipy_base.squeeze

Travis E. Oliphant oliphant at ee.byu.edu
Fri Aug 27 14:32:06 CDT 2004

Jean-Michel Philippe wrote:
> Hi,
> I recently had troubles with the squeeze function from scipy_base. It 
> squeezes all the dimensions when I pass a (1,1) array, resulting in an 
> empty one!

I don't understand the problem.  If you have a (1,1) array then 
according to the documentation squeeze should return an array with all 
dimensions of length one removed.  Therefore, you end up with a 
zero-dimensional array (this is not an empty array...)

It seems to work for me:

 >>> a = array([[5]])
 >>> a.shape
(1, 1)
 >>> b = squeeze(a)
 >>> shape(b)
 >>> b

This is not a "side effect" but a documented effect.  If you want to 
ensure a 1d array as it seems you do, then you could use

b = atleast_1d(squeeze(a))


More information about the SciPy-user mailing list