Python Practice › NumPy Programs › Program 90

Do two arrays have the same shape?

EasyNumPy Programs · 90 of 100

Write a NumPy program to check whether two arrays have the same dimensions.

Advertisement
Output
True False

Approach

  1. Compare .shape.

Solution

Python
import numpy as npa, b, c = np.zeros((2, 3)), np.ones((2, 3)), np.ones((3, 2))print(a.shape == b.shape, a.shape == c.shape)
Output
True False
Advertisement

Learn the concept

New to this topic? Read the lesson, then come back.

More numpy programs

← All 100 NumPy Programs