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

  • برمجة بايثون

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

الأجوبة

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
هل كان المحتوى مفيد؟

تبحث عن مدرس اونلاين؟

محتاج مساعدة باختيار المدرس الافضل؟ تواصل مع فريقنا الان لمساعدتك بتأمين افضل مدرس
ماهو التخصص الذي تبحث عنه؟
اكتب هنا...