在Python开头,将一个具有最大元素的Numpy阵列洗牌
我正在尝试将数组r1
洗牌,以便最大的元素始终位于r2 [0,0]
。连接电流和可能的预期输出。
import numpy as np
r1 = np.array([[150. , 132.5001244 , 115.00024881],
[ 97.50037321, 80.00049761, 62.50062201],
[ 45.00074642, 27.50087082, 10.00099522]])
r2=np.random.shuffle(r1)
print("r2 =",r2)
当前输出是
r2 = None
可能的预期输出
array([[150.,62.50062201,115.00024881],
[27.50087082,80.00049761,132.5001244]
[10.00099522,97.50037321,45.00074642]])
I am trying to shuffle the array r1
such that the largest element is always at r2[0,0]
. The current and one possible expected output is attached.
import numpy as np
r1 = np.array([[150. , 132.5001244 , 115.00024881],
[ 97.50037321, 80.00049761, 62.50062201],
[ 45.00074642, 27.50087082, 10.00099522]])
r2=np.random.shuffle(r1)
print("r2 =",r2)
The current output is
r2 = None
One possible expected output is
array([[150.,62.50062201,115.00024881],
[27.50087082,80.00049761,132.5001244]
[10.00099522,97.50037321,45.00074642]])
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
为了清楚起见,您应该继续进行以下操作:
如果
最初排序阵列,则可以使用阵列的平坦视图:
可能的输出:
For clarity, here is how you should proceed:
Alternative
If the the array is initially sorted, we can use a flat view of the array:
possible output: