# [SciPy-user] Results of squeeze function on a [1,1] size array

Michael Hearne mhearne@usgs....
Mon Oct 13 13:31:11 CDT 2008

```Didn't know there was such a thing as a 0-dim array.  It seems to
_behave_ like a scalar!

Problem solved...

Thanks,

Mike

Robert Kern wrote:
> On Mon, Oct 13, 2008 at 12:12, Michael Hearne <mhearne@usgs.gov> wrote:
>
>> Using numpy version 1.1.0.dev5077
>> Using scipy version 0.7.0.dev4174
>>
>> on Mac OS X
>>
>> If I do the following:
>> x = zeros([1,1])
>> x[0] = 3.4756
>> y = squeeze(x)
>>
>> What is y?  When I print or do arithmetic with y, it seems like it's a
>> scalar.
>>
>
> Why do you say that? It looks like a 0-dim array to me.
>
> In [1]: from numpy import *
>
> In [2]: x = zeros([1,1])
>
> In [3]: x
> Out[3]: array([[ 0.]])
>
> In [4]: x[0] = 3.4756
>
> In [5]: x
> Out[5]: array([[ 3.4756]])
>
> In [6]: y = squeeze(x)
>
> In [7]: y
> Out[7]: array(3.4756)
>
> In [8]: y.shape
> Out[8]: ()
>
>
>> However, the type() function seems to indicate that it's a
>> numpy.ndarray,  but with 0 dimensionality.
>>
>
> Yup.
>
>
>> Questions:
>> How do I detect when I'm in this state?
>>
>
> isinstance(y, numpy.ndarray) and y.shape == ()
>
>
>> How can I convert this from a (sort of) scalar into an array with length
>> of one?
>>
>
> atleast_1d(y)
>
>

--
------------------------------------------------------
Michael Hearne
mhearne@usgs.gov
(303) 273-8620
USGS National Earthquake Information Center
1711 Illinois St. Golden CO 80401
Senior Software Engineer
Synergetics, Inc.
------------------------------------------------------

```