Numpy

Numpy (57)

Jun's N 2022. 10. 19. 22:18

How to compute the min-by-max for each row for a numpy array 2d?

# Input
np.random.seed(100)
a = np.random.randint(1,10, [5,3])
a

# Solution
np.apply_along_axis(lambda x: np.min(x)/np.max(x), arr=a, axis=1)

# output
array([ 0.44444444,  0.125     ,  0.5       ,  1.        ,  0.11111111])
728x90