Helloo, I have a numpy array of (x,y,z) coordinates.
coors = [[0,0,7], [1,1,6], [2,2,6], [3,3,6], [4,4,6], [5,5,6]]
now I want to get all the 3rd element (z) of each coordinate if the (x,y) is inside a given rectangle
rect_mins = 2000,1800 # x_min, y_min rect_maxs = 2100,1900 # x_max, y_max coors [coors [:, 0] > 2000 and coors [:, 0] < 2100 and coors [:, 1] > 1800 and coors [:, 1] < 1900]
but I get this error:
ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()
How can I get rid of this error, also what is the most efficient way of doing this operation?
replace and (only checks if a statement is true) with & (performs bitwise and operation) and add Parentheses (to separate each operation)
coors [(coors [:, 0] > 2000) & (coors [:, 0] < 2100) & (coors [:, 1] > 1800) & (coors [:, 1] < 1900)]