Python Forum
Multiple conditions when indexing an array with or without np.where
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Multiple conditions when indexing an array with or without np.where
#1
Hi everyone,

I would appreciate some tips regarding my problem. There is an array (np.array) where I should find rows and columns of interesting elements. The array has values between 0 and 360

Example:

[20 20 33 360]
[54 62 27 89]
[120 200 300 54]

Now this works: r, c = np.where(array <20)

This does not: r, c = np.where(340 < array < 20) or np.where(array > 340 | array < 20 ) or np.where(array > 340 or array < 20 )

This also does not work: x = (array > 340) | array(array < 20)

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

What would be the best way to find rows and columns of elements for which multiple conditions have to be checked. Of course I could write r, c for every condition separately using np.where but that would be to many lines.

Any tips would be appreciated
Reply


Messages In This Thread
Multiple conditions when indexing an array with or without np.where - by noob2305 - Oct-25-2020, 07:42 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  [Newbie] Multiple Array azhuda 3 1,050 Jun-01-2023, 04:29 AM
Last Post: azhuda
  How do you format Update statement with multiple conditions hammer 4 2,147 Dec-16-2021, 10:49 PM
Last Post: hammer
  Indexing [::-1] to Reverse ALL 2D Array Rows, ALL 3D, 4D Array Columns & Rows Python Jeremy7 8 7,231 Mar-02-2021, 01:54 AM
Last Post: Jeremy7
  Multiple conditions, one is null moralear27 1 2,221 Sep-13-2020, 06:11 AM
Last Post: scidam
  multiple conditions Chandan 7 4,057 Jan-31-2020, 12:53 AM
Last Post: Chandan
  How to change 0 based indexing to 1 based indexing in python..?? Ruthra 2 4,526 Jan-22-2020, 05:13 PM
Last Post: Ruthra
  Help with multiple conditions on ATM program jakegold98 6 9,245 Dec-06-2017, 05:18 PM
Last Post: jakegold98
  Simplifying multiple "or" conditions in if statement. rhubarbpieguy 8 102,268 Jul-22-2017, 12:19 PM
Last Post: rhubarbpieguy

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020