Why are the following indexing forms produce differently shaped outputs?
a = np.zeros((5, 5, 5, 5))
print(a[:, :, [1, 2], [3, 4]].shape)
# (5, 5, 2)
print(a[:, :, 1:3, [3, 4]].shape)
#(5, 5, 2, 2)
Almost certain I'm missing something obvious.
Why are the following indexing forms produce differently shaped outputs?
a = np.zeros((5, 5, 5, 5))
print(a[:, :, [1, 2], [3, 4]].shape)
# (5, 5, 2)
print(a[:, :, 1:3, [3, 4]].shape)
#(5, 5, 2, 2)
Almost certain I'm missing something obvious.
In the first case: Both [1,2] and [3,4] are of shape (2,), which together result in a single (array-)dimension of shape (2,). So in the first result, you got (5,5,2), where the last (2,) is newly created during the process.
On the second case: the only list [3,4] itself results in one (array-)dimension of shape (2,). And the slicing 1:3 only changes the length of its own (array-)dimension into 2. Thus the result (5,5,2,2).