Array indexing refers to the process of accessing an element within an array.
You can retrieve an array element by using its index number. In NumPy arrays, indexing begins at 0, which means the first element is indexed as 0, the second as 1, and so on.
Retrieve the first element from the following array:
import numpy as np arr = np.array([1, 2, 3, 4]) print(arr[0]) |
Obtain the second element from the following array.
import numpy as np arr = np.array([1, 2, 3, 4]) print(arr[1]) |
Retrieve the third and fourth elements from the following array and sum them together.
import numpy as np arr = np.array([1, 2, 3, 4]) print(arr[2] + arr[3]) |