[Numpy-discussion] ZeroRank memmap behavior?
Wim Bakker
spitskip@gmail....
Mon Sep 24 09:25:59 CDT 2012
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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.scipy.org/pipermail/numpy-discussion/attachments/20120924/0fd2ba05/attachment.html
More information about the NumPy-Discussion
mailing list