Suppose I have a 3D array (tensor)
print a.shape
(100, 100, 100)
and want to index its first axis using one array:
print i.shape
(20,)
and its last axis using another array
print j.shape
(30,)
My intent is to get a (20, 100, 30) array, for example, to be used in assignments like
a[?!, :, ?!] = b
However, I can't figure out how.
print a[i.reshape(20, 1, 1), :, j.reshape(1, 1, 30)].shape
(20, 1, 30, 100)
print a[i.reshape(20, 1, 1), :, j].shape
(20, 1, 30, 100)
print a[i.reshape(20, 1), :, j].shape
(20, 30, 100)
print a[i.reshape(20, 1, 1), j.reshape(1, 1, 30)].shape
(20, 1, 30, 100)
As I understand the "advanced indexing" rules, the first attempt should have worked, but I didn't even end up with a 3D array, and the full dimension (100) came at the end instead of the middle.