在数组中交换元素
我得到了以下numpy数组:
a = np.array([
[ 0.87142134, -1.99712722, -0.17742774],
[-0.15155389, 0.0450012 , 0.23662928],
[-0.84674329, 2.34415168, 1.23702494],
[ 1.98923065, -0.02327895, 0.21864032],
[ 1.62936827, 1.39849021, 1.04613713]])
我想交换位置0和位置1之间的值,这是这样的:
array([[-1.99712722, 0.87142134, -0.17742774],
[0.0450012, -0.15155389, 0.23662928],
[2.34415168, -0.84674329, 1.23702494],
[-0.02327895, 1.98923065, 0.21864032],
[1.39849021, 1.62936827, 1.04613713]])
我尝试了以下代码,但是,它失败了:
b = a.T
b[1], b[0] = b[0], b[1]
我该如何实现此结果?
I got the below numpy array:
a = np.array([
[ 0.87142134, -1.99712722, -0.17742774],
[-0.15155389, 0.0450012 , 0.23662928],
[-0.84674329, 2.34415168, 1.23702494],
[ 1.98923065, -0.02327895, 0.21864032],
[ 1.62936827, 1.39849021, 1.04613713]])
And I would like to swap the values between position 0 and position 1, which is something like this:
array([[-1.99712722, 0.87142134, -0.17742774],
[0.0450012, -0.15155389, 0.23662928],
[2.34415168, -0.84674329, 1.23702494],
[-0.02327895, 1.98923065, 0.21864032],
[1.39849021, 1.62936827, 1.04613713]])
I tried the code as follows, however, it failed:
b = a.T
b[1], b[0] = b[0], b[1]
How could I achieve this result?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用:
输出:
you can use:
output: