Curriculum
Course: NumPy
Login

Curriculum

NumPy

Text lesson

NumPy Array Indexing

Access Array Elements

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.

Example

Retrieve the first element from the following array:

import numpy as np

arr = np.array([1234])

print(arr[0])

Example

Obtain the second element from the following array.

import numpy as np

arr = np.array([1234])

print(arr[1])

Example

Retrieve the third and fourth elements from the following array and sum them together.

import numpy as np

arr = np.array([1234])

print(arr[2] + arr[3])