Numpy

Numpy (55)

알 수 없는 사용자 2022. 10. 14. 22:18
728x90

How to rank items in a multidimensional array using numpy?

# Input:
np.random.seed(10)
a = np.random.randint(20, size=[2,5])
print(a)

# Solution
print(a.ravel().argsort().argsort().reshape(a.shape))

# output
 [[ 9  4 15  0 17]
  [16 17  8  9  0]]
 [[4 2 6 0 8]
  [7 9 3 5 1]]