Hi All I want to get out the index of values in an array. Normally WHERE works fine for one conditional statement but it does not work for two - i.e. a = array([0,1,2,3,4,5,6,7,8,9]) ind, = where(a > 5) Works fine but if I wanted: ind = where((a > 5) and (a<8)) Then it bugs out with the following message: "The truth value of an array with more than one message is ambiguous" Any ideas? Cheers Ross
Ross Williamson wrote:
Hi All
I want to get out the index of values in an array. Normally WHERE works fine for one conditional statement but it does not work for two - i.e.
a = array([0,1,2,3,4,5,6,7,8,9])
ind, = where(a > 5)
Works fine but if I wanted:
ind = where((a > 5) and (a<8))
Python/numpy wart: for fairly fundamental Python reasons, "and" does not work elementwise so you have to use the "&" operator instead: ind = where((a > 5) & (a<8)) Same for "or" and "|". Parentheses as you have them are essential because of the precedence of the bit operators. Eric
Then it bugs out with the following message:
"The truth value of an array with more than one message is ambiguous"
Any ideas?
Cheers
Ross _______________________________________________ Numpy-discussion mailing list Numpy-discussion@scipy.org http://projects.scipy.org/mailman/listinfo/numpy-discussion
participants (2)
-
Eric Firing
-
Ross Williamson