0

Hi everybody I am new at this forum, teaching technology since 2006 and before programming in diferent companies. I came from visual basic and now I am diving into python. I have found the next problem when trying to use numpy where method.

 f"Cannot perform '{op.__name__}' with a dtyped [{x.dtype}] array "

TypeError: Cannot perform 'ror_' with a dtyped [float64] array and scalar of type [bool]

The code is this one

df['Value']=np.where((df['ValA']>0.01) & (df['ValB']>df['ValC']) & (df['ValB'].shift(1) > 0.8) & (df['ValB'] < 0.8) & (df['ValD'] > 0.02 | df['ValD'].shift(1) > 0.02 | df['ValD'].shift(2)> 0.02), 1, 0)

Everything was working fine untill I used =>

(df['ValD'] > 0.02 | df['ValD'].shift(1) > 0.02 | df['ValD'].shift(2)> 0.02)

as a part of the operator

Thanks in advance!!

Dhaval Taunk
  • 1,662
  • 1
  • 9
  • 17
Mikelatz
  • 1
  • 1
  • I believe the `|` operator has higher precedence than `>` operator (due to it being intended as bitwise but stats libraries use it for element wise logical) so you would need to parentheses the comparisons. – Tadhg McDonald-Jensen Jul 08 '20 at 16:52
  • 1
    Perfect!!! I have tryied it, puting parentheses in each element before "|" operator as you said. It works fine. Thank you very much!!! – Mikelatz Jul 08 '20 at 17:04
  • I voted to close as a duplicate instead of "caused by typo" since linking this question to that one will likely be more helpful to others. – Tadhg McDonald-Jensen Jul 08 '20 at 17:11

0 Answers0