Q:

Write a NumPy program to get the index of a maximum element in a numpy array along one axis

0

Write a NumPy program to get the index of a maximum element in a numpy array along one axis.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

import numpy as np    
a = np.array([[1,2,3],[4,3,1]])
print("Original array:")
print(a)
i,j = np.unravel_index(a.argmax(), a.shape)
print("Index of a maximum element in a numpy array along one axis:")
print(a[i,j])

Sample Output:

Original array:
[[1 2 3]
 [4 3 1]]
Index of a maximum element in a numpy array along one axis:
4

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now