Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

numpy select all elements from under array

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 ?

like image 203
Max0u Avatar asked May 16 '26 21:05

Max0u


1 Answers

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.

like image 165
Will Da Silva Avatar answered May 18 '26 09:05

Will Da Silva



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!