numpy数组中每行的最小值[duplicate]

0vvn1miw  于 2022-12-13  发布在  其他
关注(0)|答案(2)|浏览(165)

此问题在此处已有答案

Extracting minimum values per row using numpy(1个答案)
昨天关门了。
我有一个numpy数组,想计算每一行中的最小值:

import numpy as np

data=np.array([[ 9.052878e+07,  1.666794e+08,  9.783935e+07,  7.168723e+07],
       [ 1.033552e+04,  1.902951e+04,  1.117015e+04,  8.184407e+03],
       [ 1.000000e+15,  5.740625e+15,  3.419288e+15,  2.549149e+15],
       [ 1.000000e+15,  5.740625e+15,  3.419288e+15,  2.549149e+15]])

print(np.min(data))
#8184.407

np.min(data)规定了总最小值,而不是按行。

ki0zmccv

ki0zmccv1#

这个对你有用吗

import numpy as np

data=np.array([[ 9.052878e+07,  1.666794e+08,  9.783935e+07,  7.168723e+07],
       [ 1.033552e+04,  1.902951e+04,  1.117015e+04,  8.184407e+03],
       [ 1.000000e+15,  5.740625e+15,  3.419288e+15,  2.549149e+15],
       [ 1.000000e+15,  5.740625e+15,  3.419288e+15,  2.549149e+15]])
np.amin(data, axis=-1)
# array([7.168723e+07, 8.184407e+03, 1.000000e+15, 1.000000e+15])
7kqas0il

7kqas0il2#

如果您需要每行最小值,请提及axis -np.min with axis

print(data.min(axis=1))

相关问题