0

So I have a 2D matrix, in the code called wave[2] (it's the place-2 element of the three-dimensional array wave), which I want to map into a matrix of equal dimensions but with the condition that if the element I am mapping is between -0.001 and 0.001 I will map it into a 0, otherwise I will map into a np.nan value. This is what I wrote to do so:

zeros=np.array(n,n)
zeros[wave[2] < 0.01 and wave[2] > -0.01] = 0
zeros[wave[2] > 0.01 or wave[2] < -0.01] = np.nan

But I guess passing two conditions inside the brackets is not legal, because I get this error message: ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all(). I'm not able to fix it.

  • maybe - `np.logical_and(wave[2] < 0.01, wave[2] > -0.01)` or `wave[2] < 0.01 & wave[2] > -0.01` – wwii Jun 13 '22 at 21:34
  • 1
    Related (dupe?): [Logical operators for Boolean indexing in Pandas](https://stackoverflow.com/questions/21415661/logical-operators-for-boolean-indexing-in-pandas), and [& vs * and | vs +](https://stackoverflow.com/questions/14679595/vs-and-vs) – wwii Jun 13 '22 at 21:38

0 Answers0