I've beeen taking deep learning course on coursera. While I was doing my assignment I saw one piece of code on the github.
1. numpyArr[...,c]
2. numpyArr[:,:,:,c]
What is the difference between these slicing methods?
I've beeen taking deep learning course on coursera. While I was doing my assignment I saw one piece of code on the github.
1. numpyArr[...,c]
2. numpyArr[:,:,:,c]
What is the difference between these slicing methods?
If both arrays have 4 dimensions there is no difference in the result. However, if you do not really care about the number of dimensions, using the Ellipsis (...) just indicates any number of dimensions. So the first version means:
"get all dimensions but from the last one (whatever the last is) only entry c
"
and the second means
"get dimensions 0, 1, 2 complete and from dimension 3 only entry c
.
Which is the same for a 4-d array but different for a 5d array.
For an array with many dimensions even more fun is possible:
arr = np.random.uniform(size=(3, 3, 3, 3, 3))
print(arr[1, ..., 2, 3].shape)
Which means: get the second entry on the first dimension and of that entry 2 and 3 of the two last dimensions with everything in between.
Some years ago, this has already been asked, but one needs to know that ...
is the Ellipsis.