[SciPy-user] Results of squeeze function on a [1,1] size array
Mon Oct 13 12:16:10 CDT 2008
On Mon, Oct 13, 2008 at 12:12, Michael Hearne <firstname.lastname@example.org> 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 = 3.4756
> y = squeeze(x)
> What is y? When I print or do arithmetic with y, it seems like it's a
Why do you say that? It looks like a 0-dim array to me.
In : from numpy import *
In : x = zeros([1,1])
In : x
Out: array([[ 0.]])
In : x = 3.4756
In : x
Out: array([[ 3.4756]])
In : y = squeeze(x)
In : y
In : y.shape
> However, the type() function seems to indicate that it's a
> numpy.ndarray, but with 0 dimensionality.
> 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?
"I have come to believe that the whole world is an enigma, a harmless
enigma that is made terrible by our own mad attempt to interpret it as
though it had an underlying truth."
-- Umberto Eco
More information about the SciPy-user