-1

I want to set all the values between 0.75 and 0.8 of an array, equal to zero. Until now I have tried and succeeded to set all the values below or above a threshold equal to zero as it presented in the following code. cut_f_signal[0.75<abs(W)] = 0 but when I try with same command to put a range of values (0.75-0.8), cut_f_signal[0.75<abs(W)<0.8] = 0 , it doesn't work, what shall I do?

pantelis
  • 83
  • 6
  • Hi pantelis. Could you add a [mre] to your question? That would probably help to get the question reopened and/or upvoted. – wovano Nov 28 '20 at 09:44
  • Actually, this question seems to be a duplicate of https://stackoverflow.com/questions/31617845/how-to-select-rows-in-a-dataframe-between-two-values-in-python-pandas (since the answer is also copied from that question) – wovano Nov 28 '20 at 09:47

1 Answers1

1

cut_f_signal[(0.75<abs(W))&(abs(W)<0.8)] = 0 Should do it

ombk
  • 2,036
  • 1
  • 4
  • 16
  • Could you explain why this works, instead of only posting the code? That will be more useful for others. In general, in Python `a < b < c` is valid (even though I don't know what `W` is in this example), so I'm wondering why this is different. – wovano Nov 28 '20 at 09:33
  • @wovano to avoid having the ambiguity error the one that says `.any() .all() ...` you can easily separate and put your 2 conditions between brackets. I believe his `W` was a filtered dataframe on a column with certain values that need to be in `abs` so basically his `W = df["W"]` or something like this – ombk Nov 28 '20 at 09:36
  • 1
    https://stackoverflow.com/questions/31617845/how-to-select-rows-in-a-dataframe-between-two-values-in-python-pandas/40442778 read more here if interested – ombk Nov 28 '20 at 09:37
  • Thanks for your reaction. However, if the question already was answered you should have flagged the question as a duplicate. That way, all answers can be found at the same place, which would improve the quality of the site. The answers of the original questions provide better explanations and alternative solutions as well. – wovano Nov 28 '20 at 09:50