[Numpy-discussion] problem: I get an array that doesn't have a length
Francesc Altet
faltet at carabos.com
Wed May 2 11:39:29 EDT 2007
El dc 02 de 05 del 2007 a les 09:52 -0400, en/na Pierre GM va escriure:
> Mark,
> In your example:
> > >>> b = asarray(3,'d')
>
> b is really a numpy scalar, so it doesn't have a length. But it does have a
> size (1) and a ndim (0).
Just one correction in terms of the current naming convention: b in this
case is a 0-dim array, which is a different beast than a numpy scalar
(although they behaves pretty similarly). You can distinguish between
them in different ways, but one is using type():
In [24]:type(numpy.asarray(3.)) # a 0-dim array
Out[24]:<type 'numpy.ndarray'>
In [25]:type(numpy.float64(3.)) # a numpy scalar
Out[25]:<type 'numpy.float64'>
Cheers,
--
Francesc Altet | Be careful about using the following code --
Carabos Coop. V. | I've only proven that it works,
www.carabos.com | I haven't tested it. -- Donald Knuth
More information about the NumPy-Discussion
mailing list