1

index = np.where(slopes > mean - 2 * sd and slopes < mean + 2 * sd)[0]

returns this error:

ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()

If I instead write idx = np.where(slopes < mean + 2 * sd)[0] or idx = np.where(slopes > mean - 2 * sd)[0] I get the right indices. Why can't I combine both conditions?

hmnoidk
  • 545
  • 6
  • 20
  • 1
    Does this answer your question? [ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()](https://stackoverflow.com/questions/10062954/valueerror-the-truth-value-of-an-array-with-more-than-one-element-is-ambiguous) – iacob Apr 19 '21 at 14:31

1 Answers1

1

Instead of using boolean 'and':

index = np.where((slopes > mean - 2 * sd) and (slopes < mean + 2 * sd))[0]

Try your code with bitwise '&':

index = np.where((slopes > mean - 2 * sd) & (slopes < mean + 2 * sd))[0]

Note: For more Information regarding boolean 'and' and bitwise '&' you can refer to this Question

Anurag Dabas
  • 23,866
  • 9
  • 21
  • 41