Answers for "numpy multidimensional indexing"

0

numpy multidimensional indexing

# Let's say you have a batch of 256 inputs, each one has a set of 64 points.
x.shape --> (256, 64, 3)

# Now assume you want to index each image and draw 128 samples of those points,
# with an indices matrix.
idx.shape --> (256, 128)

# Do
y = x[np.arange(x.shape[0]), idx.T].reshape((1, 0, 2))
y.shape --> (256, 128, 3)
Posted by: Guest on February-09-2022

Python Answers by Framework

Browse Popular Code Answers by Language