Thanks Sebastian. Casting it to an array would certainly help.

Another oddity of zero-ranked scalars is that they look iterable, but in
fact are not. Because all they do is generate an error.

>>> a = np.array(22)

Test if iterable:

>>> hasattr(a, __iter__)
True

Or:

>>> import collections
>>> isinstance(a, collections.Iterable)
True

>>> for e in a:
print e
TypeError: iteration over a 0-d array

Wouldn't it be better to have a different type altogether for numpy
scalars? Because scalars don't seem to quack quite like arrays...
(I haven't been following the discussion around scalars, so if this is a
silly remark just ignore it)

Another question. What would be the preferred method of testing for
zero-ranked array?
Something like this?

>>> if a.shape:
print "array"
else:
print "scalar"

Regards,

Wim
_______________________________________________
NumPy-Discussion mailing list
[email protected]
http://mail.scipy.org/mailman/listinfo/numpy-discussion

Reply via email to