[Numpy-discussion] The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()
Rick Muller
rpmuller at gmail.com
Wed Oct 27 16:58:32 EDT 2010
Help! I'm having a problem in searching through the *elements* if a 2d
array. I have a loop over a numpy array:
n,m = G.shape
print n,m
for i in xrange(n):
for j in xrange(m):
print type(G), type(G[i,j]), type(float(G[i,j]))
g = float(abs(G[i,j]))
if g < cut:
print i,j,G[i,j]
However, I'm getting the error message:
The truth value of an array with more than one element is ambiguous. Use
a.any() or a.all()
despite the fact that I'm not computing a truth value of an array. I'd like
to just compare to G[i,j] or abs(G[i,j]), which should be a *single* value,
and *not* an array. I even call 'float' here to make sure that I cast this
to a normal python float. But I still get this error message.
At this point, I suspect that I'm doing something dumb, rather than
discovering some unique bug in numpy. Can anyone help me out?
--
Rick Muller
rpmuller at gmail.com
505-750-7557
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20101027/828eb49f/attachment.html>
More information about the NumPy-Discussion
mailing list