In this python numpy program, we will check whether the dimensions of two arrays are the same or not.
Steps to solve the program
- Import the numpy library as np.
- Create two arrays using np.array().
- Use an if-else statement with shape to check whether the dimensions of two arrays are the same or not.
- Print the output.
import numpy as np
x = np.arange(15).reshape(3,5)
y = np.arange(20).reshape(4,5)
if x.shape == y.shape:
print("Same dimensions")
else:
print("Different dimensions")
Output :
Different dimensions