# [Numpy-discussion] possible bug with numpy.object_

Christopher Barker Chris.Barker at noaa.gov
Thu Aug 31 11:46:06 CDT 2006

```Fernando Perez wrote:
> In [8]: N.array(3).shape
> Out[8]: ()

> In [11]: N.array([]).shape
> Out[11]: (0,)

> I guess my only remaining question is: what is the difference between
> outputs #8 and #11 above?  Is an empty shape tuple == array scalar,
> while a (0,) shape indicates a one-dimensional array with no elements?
>  If this interpretation is correct, what is the usage of the latter
> kind of object, given how it can't even be indexed?

It can be iterated over (with zero iterations):

>>> a = N.array([])
>>> for i in a:
...   print i
...

whereas the scalar can not:

>>> b = N.array(3)
>>> b
array(3)
>>> for i in b:
...   print i
...
Traceback (most recent call last):
File "<stdin>", line 1, in ?
TypeError: iteration over a scalar (0-dim array)

Of course the scalar isn't empty, so ti's different in that way too. Can
there be an empty scalar? It doesn't look like it. In fact, this looks
like it may be a bug:
>>> a = N.array([1,2,3]).sum(); a.shape; a.size; a
()
1
6

That's what I'd expect, but what if you start with a (0,) array:
>>> a = N.array([]).sum(); a.shape; a.size; a
()
1
0

where did that zero come from?

>>> N.__version__
'1.0b4'

-Chris

--
Christopher Barker, Ph.D.
Oceanographer

NOAA/OR&R/HAZMAT         (206) 526-6959   voice
7600 Sand Point Way NE   (206) 526-6329   fax
Seattle, WA  98115       (206) 526-6317   main reception

Chris.Barker at noaa.gov

```

More information about the Numpy-discussion mailing list