import numpy as np
data = np.sin(np.arange(20)).reshape(5,4)
print(data)
ind = data.argmax(axis=0)
print(ind)
data_max = data[ind,range(data.shape[1])]
print(data_max)
all(data_max == data.max(axis=0))
[[ 0. 0.84147098 0.90929743 0.14112001]
[-0.7568025 -0.95892427 -0.2794155 0.6569866 ]
[ 0.98935825 0.41211849 -0.54402111 -0.99999021]
[-0.53657292 0.42016704 0.99060736 0.65028784]
[-0.28790332 -0.96139749 -0.75098725 0.14987721]]
[2 0 3 1]
[0.98935825 0.84147098 0.99060736 0.6569866 ]
True
a = np.arange(0,40,10)
b = np.tile(a,(3,5))
print(a)
print(b)
[ 0 10 20 30]
[[ 0 10 20 30 0 10 20 30 0 10 20 30 0 10 20 30 0 10 20 30]
[ 0 10 20 30 0 10 20 30 0 10 20 30 0 10 20 30 0 10 20 30]
[ 0 10 20 30 0 10 20 30 0 10 20 30 0 10 20 30 0 10 20 30]]
a = np.array([[4,3,5],[1,2,1]])
print(a)
b = np.sort(a,axis=1)
print(b)
a.sort(axis=1)
print(a)
print("---")
a = np.array([4,3,1,2])
j = np.argsort(a)
print(j)
print(a[j])
[[4 3 5]
[1 2 1]]
[[3 4 5]
[1 1 2]]
[[3 4 5]
[1 1 2]]
---
[2 3 1 0]
[1 2 3 4]