0

I want to remove, from a np array, two values - 0 and 'Draw'. But, I am receiving the below error message. I realize I could remove the values using index positions, but for a large array it would be tiresome. Is there a way to fit the np.where condition to achieve this? I went through this answer, but couldn't understand. ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()

Team_Names = np.delete(Team_Names, np.where(Team_Names == [0] or  Team_Names == ['Draw']))

Team Names array

enter image description here

Henry Ecker
  • 34,399
  • 18
  • 41
  • 57
  • Can you show us what the array `Team_Names` is? is it an 1-D array or multidimensional? Normally you can not use `or` when you want to get the element-wise `or` of two arrays, instead you should use `|` operator. – Woods Chen Jun 19 '20 at 08:31
  • Hi Woods, Thanks for your reply. I have added the print of Team_Names above. I replaced the or with | & am facing this error: 'TypeError: unsupported operand type(s) for |: 'int' and 'str'' –  Jun 19 '20 at 09:47
  • Because `|` operator is prior to `==` operator, so `[0] | Team_Names` will be executed first when `Team_Names == [0] | Team_Names == ['Draw']` is being executed, thus `TypeError` is raised because we can not use `|` operator between string objects and int objects. To solve this, add some parenthesis to change the priority of operaings: `(Team_Names == 0) | (Team_Names == 'Draw')` – Woods Chen Jun 21 '20 at 04:57
  • @Woods, Thanks a ton. Understood. –  Jun 21 '20 at 08:19

0 Answers0