19 lines
481 B
Python
19 lines
481 B
Python
import numpy as np
|
|
array_2d = np.array([
|
|
[1, 2, 3, 4],
|
|
[5, 6, 7, 8],
|
|
[9, 10, 11, 12]
|
|
])
|
|
print(array_2d[1:])
|
|
print(array_2d[:, 0])
|
|
print(array_2d[1:, 1:-1])
|
|
print(array_2d[:-1, ::2])
|
|
print(array_2d[2, ::-2])
|
|
|
|
array = np.array([23, 41, 7, 80, 3])
|
|
# Retrieving elements at indices 0, 1 and 3
|
|
print(array[[0, 1, 3]])
|
|
# Retrieving elements at indices 1, -1 and 2 in this order
|
|
print(array[[1, -1, 2]])
|
|
# IndexError is thrown since index 5 is out of bounds
|
|
print(array[[2, 4]]) |