I don't want to use a loop to achieve this, wondering if there is a numpy method.
I want to modify the minimum or maximum value of each row to a specified value
Suppose it is changed to -1
I don't want to use a 'for' loop since there are millions of rows
arr = np.array([[1, 2, 3],
[6, 5, 4],
[7, 8, 9],
[15, 12, 43],
[2, 2, 2],
[2, 2, 1],
[1, 2, 1],
])
min_arr = np.min(arr, axis=1) # [ 1 4 7 12 2 1 1]
# result
[[-1 2 3]
[ 6 5 -1]
[-1 8 9]
[15 -1 43]
[-1 -1 -1]
[ 2 2 -1]
[-1 2 -1]]