Curriculum
Course: NumPy
Login

Curriculum

NumPy

Text lesson

Iterating 2-D Arrays

In a 2-D array, it will iterate through all the rows.

Example

Iterate through the elements of the following 2-D array:

import numpy as np

arr = np.array([[123], [456]])

for x in arr:
  print(x)

To obtain the actual values, or scalars, we need to iterate through the arrays in each dimension.

Example

Iterate through each scalar element of the 2-D array:

import numpy as np

arr = np.array([[123], [456]])

for x in arr:
  for y in x:
    print(y)