I have an np.array with 3 dimension. I just want to select all n-th element from the last array.
I know that I can select it like
array[:, :, 0]
But I need to use a function, is there any numpy function to do that ?
I have an np.array with 3 dimension. I just want to select all n-th element from the last array.
I know that I can select it like
array[:, :, 0]
But I need to use a function, is there any numpy function to do that ?
The [] operator calls __getitem__ on the object it was used on. In your case, it would be the equivalent of calling
array.__getitem__((slice(None), slice(None), 0))
This is because [:] is an empty slice (i.e. slice(None)), and you are calling the [] operator with 3 value, which is equivalent to calling __getitem__ with a tuple of 3 values.
[] operator.