Following is a way to do this in a single pass, unlike other answers here that first find the max and then search for it.
This solution finds the INDEX of the max value in each row, then assigns 0 to that index.
import numpy as np
x = np.random.uniform(1.0, 21.0, 20)
print("Original array: ", x)
xMatrix = x.reshape(4, 5)
print(xMatrix)
gives
xMatrix
Out[28]:
array([[10.10437809, 6.4552141 , 15.1040498 , 1.94380305, 15.27380855],
[12.08934681, 19.20744506, 14.12271304, 8.45470779, 6.2887767 ],
[ 7.74326665, 14.63460522, 12.07651464, 15.80510958, 2.24595519],
[16.12620326, 16.29083185, 7.96133555, 10.61357712, 14.6664017 ]])
then
max_ind = np.argmax(xMatrix, axis=1)
row_ind = np.arange(xMatrix.shape[0])
multi_ind = np.array([row_ind, max_ind])
linear_ind = np.ravel_multi_index(multi_ind, xMatrix.shape)
xMatrix.reshape((-1))[linear_ind] = 0
xMatrix
Out[37]:
array([[10.10437809, 6.4552141 , 15.1040498 , 1.94380305, 0. ],
[12.08934681, 0. , 14.12271304, 8.45470779, 6.2887767 ],
[ 7.74326665, 14.63460522, 12.07651464, 0. , 2.24595519],
[16.12620326, 0. , 7.96133555, 10.61357712, 14.6664017 ]])