I have a numpy array and want to calculate the minimum in each row:
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)
claulates the total minimum and not row-wise.
CodePudding user response:
Will this work for you
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])
CodePudding user response:
if you want min for each row then mention axis - np.min with axis
print(data.min(axis=1))