[SciPy-user] scipy_base.squeeze

Jean-Michel Philippe jean-michel.philippe at irsid.arcelor.com
Mon Aug 30 02:00:01 CDT 2004

Ok, this is due to the Matlab way of thinking I have.

Obviously in Python/SciPy scalars are not a particular case of arrays 
and I understood that shape(b) = () in your example just means that. 
Couldn't this be a cause of type conversion issues, for example when a 
function returns a double or an array depending on the input data? (and 
squeeze seems to be a good example for that)


NB: note that help(squeeze) just tells

% Help on function squeeze in module scipy_base.shape_base:
%    Returns a with any ones from the shape of a removed

which does not mean that the type of 'a' could be the same or could be 
changed depending on the result.

oliphant at ee.byu.edu wrote:
> 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