Python Chapter Seven After-Class Exercises plus(7)

Complete the function fun7, the parameter v is an n*m matrix (a two-dimensional list, each number is an integer from 0-10), find the absolute value of the difference between the maximum value and the minimum value in each row, and the return type is a Numpy array. And return the index of the row where the largest absolute value is located.

def fun7(v):
    '''
    Arg
    v: a 3*3 matrix ; return the difference between the maximum and minimum of each row and number of rows with maximum difference
    eg
    [[3, 2, 7],
    [2, 8, 4],
    [9, 6, 1]]
    return  (array([5 6 8]), 2)
    '''
    #因为每个数都是0-10,所以这里不需要abs函数
    diff=np.max(v,axis=1)-np.min(v,axis=1)
    return (diff,int(np.where(diff==np.max(diff))[0]))

Guess you like

Origin blog.csdn.net/qq_53029299/article/details/115281868