I have the following fragment of python code:
import numpy as np
# Some random array
x = np.random.rand(34, 176, 256)
# Get some indexes
pos_idx = np.argwhere(x > 0.5)
# Sample some values from these indexes
seeds = pos_idx[np.random.choice(pos_idx.shape[0], size=5, replace=False), :]
# Now create another array
y = np.zeros_like(x, np.uint8)
y[seeds] = 1
The last line given an error something along the lines of:
index 77 is out of bounds for axis 0 with size 34
But I am not sure how this can happen as all the sampled indexes should be valid as they are a subset.
argwherecannot be used directly to index an array. The output ofnp.whereis designed for that.np.whereapproach?