Write a NumPy program to check whether the dimensions of two given arrays are same or not.
import numpy as np def test_array_dimensions(ar1,ar2): try: ar1 + ar2 except ValueError: return "Different dimensions" else: return "Same dimensions" ar1 = np.arange(20).reshape(4,5) ar2 = np.arange(20).reshape(4,5) print(test_array_dimensions(ar1, ar2)) ar1 = np.arange(20).reshape(5,4) ar2 = np.arange(20).reshape(4,5) print(test_array_dimensions(ar1, ar2))
Sample Output:
Same dimensions Different dimensions
total answers (1)
start bookmarking useful questions and collections and save it into your own study-lists, login now to start creating your own collections.
Sample Output:
need an explanation for this answer? contact us directly to get an explanation for this answer