Conditional search returning tuples of arrays for 1D arrays?
numpy, python
Solution
I think it's for consistency, consider a 2D array:
import numpy as np
my_array = np.random.randint(1,10, (4, 5))
pos = np.where(my_array > 5)
my_array[pos]
you can use the tuple as the index to select out all the values in the locations.
Problem
I read the documentation on numpy's where, and I don't understand why `where` would return a tuple nesting an array if I am checking a condition on a simple 1D array. ``` > import numpy as np > my_array = np.random.randint(1,10, (20)) > np.where(my_array > 5) (array([ 0, 1, 4, 6, 7, 8, 10, 11, 13, 15, 16, 17, 18]),) ``` Why does `np.where` return a tuple in this case? Why nest the result?