Advanced Array Indexing¶
In [1]:
%pip install numpy
import numpy as np
Requirement already satisfied: numpy in /home/samrat/Documents/numpy-torch-tutorials/venv/lib/python3.8/site-packages (1.24.4) Note: you may need to restart the kernel to use updated packages.
In [4]:
foo = np.arange(3*2*4).reshape((3,2,4))
print(foo[:, :, 0])
print(foo[:, :, [0,1]])
[[ 0 4] [ 8 12] [16 20]] [[[ 0 1] [ 4 5]] [[ 8 9] [12 13]] [[16 17] [20 21]]]
In [5]:
foo[[0,0,2,2], :, [[0], [1], [2]]]
Out[5]:
array([[[ 0, 4],
[ 0, 4],
[16, 20],
[16, 20]],
[[ 1, 5],
[ 1, 5],
[17, 21],
[17, 21]],
[[ 2, 6],
[ 2, 6],
[18, 22],
[18, 22]]])