[SciPy-user] scipy_base.squeeze

Travis E. Oliphant oliphant at ee.byu.edu
Fri Aug 27 15:32:06 EDT 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
5
 >>>


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))

-Travis




More information about the SciPy-User mailing list