I am experimenting with Numpy features and want to know if there is a way to achieve the desired behavior as explained. Given a numpy array as shown below
array = np.array([[1,3,3],[6,7,6],[9,9,4]])
print(array)
Output from print(array)
[[1 3 3]
[6 7 6]
[9 9 4]]
I am getting the maximum in each row
max_array = array.max(axis=1,keepdims=1)
print(max_array)
Output from print(max_array)
[[3]
[7]
[9]]
I am applying the mask on all the maximum elements in the array using the code below
masked_array = np.ma.masked_equal(array,max_array)
print(masked_array)
Output from print(masked_array)
[[1 -- --]
[6 -- 6]
[-- -- 4]]
Now that I have masked the array, I want to perform operation to the non-max elements in the array like multiplication by 3 as show in the code below
mul_array= np.multiply(masked_array,3)
print(mul_array)
Output from print(mul_array)
[[3 -- --]
[18 -- 18]
[-- -- 12]]
I want to insert the maximum elements in the max_array which were masked earlier in the same position in the mul_array, but I couldn't find anything to achieve the desired behavior. Below is my expected matrix. I wanted to ask if there are any Numpy operation to achieve the desired behavior
Desired output
[[3 3 3]
[18 7 18]
[9 9 12]]
Thank you for helping!
np.ma.masked_equal(a,b)- what areaandb?