Issue
I want to locate the largest element of r2
and swap it with the element at r2[0,0]
. I present the expected output.
import numpy as np
r2 = np.array([[ 1.00657843, 63.38075613, 312.87746691],
[375.25164461, 500. , 125.75493382],
[437.6258223 , 250.50328922, 188.12911152]])
indices = np.where(r2 == r2.max())
The expected output is
array([[ 500., 63.38075613, 312.87746691],
[375.25164461, 1.00657843, 125.75493382],
[437.6258223 , 250.50328922, 188.12911152]]
Solution
You can store the maximum value in a variable, and then assign the [0, 0]
element to the indices which you found with where
and then set the [0, 0]
element to the stored maximum value:
maximum = r2.max()
indices = np.where(r2 == maximum)
r2[indices] = r2[0, 0]
r2[0, 0] = maximum
r2
Output:
array([[500. , 63.38075613, 312.87746691],
[375.25164461, 1.00657843, 125.75493382],
[437.6258223 , 250.50328922, 188.12911152]])
Answered By - Nin17
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.