Projects/3D_array_indexing.py
2025-09-12 20:37:36 -07:00

17 lines
598 B
Python

import numpy as np
array_3d = np.array([
[[1, 2, 3], [4, 5, 6]],
[[7, 8, 9], [10, 11, 12]],
[[13, 14, 15], [16, 17, 18]]
])
# Retrieving the first and second element of the first row in the second 2D array
#print(array_3d[0, 1, [0, 1]])
# Retrieving the first and second element of the second row in the second 2D array
#print(array_3d[1, 1, [0, 1]])
# Retrieving the first and second element of the second row in the third 2D array
#print(array_3d[2, 1, [0, 1]])
#accessing the main diagonal elements across the 3D array
print(array_3d[[0, 1, 2], [0, 1, 1], [0, 1, 2]])