Issue
When the dimension is known, the task is trivial. Take a 2D array:
a = np.random.randint(10, a=(5,2))
a[np.random.choice(a.shape[0]), :]
However, in my function, the dimension of the array is arbitrary. How to handle this situation?
Solution
use the size of the 1st dimension to determine the random range:
a[np.random.randint(0,a.shape[0],10)]
or if you prefer, include an Ellipsis
a[np.random.randint(0,a.shape[0],10),...]
1 indexing array selects from rows by default.
Answered By - hpaulj
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.