Lets say we have this array and I want to replace the minimum value with number 50
import numpy as np
numbers = np.arange(20)
numbers[numbers.min()] = 50
So the output is [50,1,2,3,....20]
But now I have problems with this:
numbers = np.arange(20).reshape(5,4)
numbers[numbers.min(axis=1)]=50
to get [[50,1,2,3],[50,5,6,7],....]
However I get this error:
IndexError: index 8 is out of bounds for axis 0 with size 5 ....
Any ideas for help?
You need to use
numpy.argmin
instead ofnumpy.min
:(I believe my original answer was incorrect, I confused rows and columns, and this is right)