Код:
a = np.array([[33,77,43],[32,33,55],[56,68,43],[45,45,67],[33,23,5]])
b=a.T
p=np.array([12,16,10,14,15])
def eachsales(position,price):
print('each salesman total amount',np.sum((position*price),axis=1))
i=np.where(np.sum((position*price),axis=1)==np.max(np.sum((position*price),axis=1)))
print('the amount of salesman',i,'is the highest')
eachsales(b,p)
Я узнал максимум и знал, где он находится.
Он сказал мне, что он находится на array([1], но я надеюсь, что он может вывести 1 (числовой).
И если это «1», выведите «продажи A». Если это «2», выведите «продажи B» и так далее.
each salesman total amount [2593 3107 2839]
the amount of salesman (array([1], dtype=int64),) is the highest






Попробуй это:
import warnings
warnings.filterwarnings("ignore")
import numpy as np
import string
a = np.array([[33,77,43],[32,33,55],[56,68,43],[45,45,67],[33,23,5]])
b=a.T
p=np.array([12,16,10,14,15])
def eachsales(position,price):
print('each salesman total amount',np.sum((position*price),axis=1))
i=np.where(np.sum((position*price),axis=1)==np.max(np.sum((position*price),axis=1)))
print('the amount of salesman','Sales %s'%string.ascii_uppercase[i[0]-1],'is the highest')
eachsales(b,p)
Выход:
each salesman total amount [2593 3107 2839]
the amount of salesman Sales A is the highest
Для этого не нужно использовать np.where(). Вместо этого используйте функцию np.argmax(), она напрямую возвращает индекс. Попробуйте следующий код:
import numpy as np
import string
a = np.array([[33,77,43],[32,33,55],[56,68,43],[45,45,67],[33,23,5]])
b = a.T
p = np.array([12,16,10,14,15])
def eachsales(position,price):
print('each salesman total amount',np.sum((position*price),axis=1))
i = np.argmax(np.sum((position*price),axis=1))
print('the amount of salesman','Sales %s'%string.ascii_uppercase[i],'is the highest')
eachsales(b,p)