python - 更改 numpy 中矩阵的顺序

标签 python numpy matrix linear-algebra

我有一个矩阵

test = np.array([[0,1,0,0],[1,0,1,1],[0,1,0,1],[0,1,1,0]])

如何对列重新排序,使它们像这个矩阵一样? (基本上最后一行以相反的顺序成为第一行,依此类推......)

np.array([[0,1,1,0],[1,0,1,0],[1,1,0,1],[0,0,1,0]])

最佳答案

只需反转两个轴即可

test[::-1,::-1]
array([[0, 1, 1, 0],
       [1, 0, 1, 0],
       [1, 1, 0, 1],
       [0, 0, 1, 0]])

关于python - 更改 numpy 中矩阵的顺序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58782971/

相关文章:

python - 将 numpy 数组值从零更改为 -1

python - 从第三方 api 返回项目列表的 DRF 方式是什么?

numpy - 如何比较两个 Numpy.datetime64 的日期

algorithm - matlab中的二进制3D模糊矩阵

matplotlib - 如何将多个 matshow() 结果放在一张图中?

python - 无法准确抓取google新闻

python - 欧氏距离的迭代计算

python - 如何使用作为其他回归函数之和的多元回归函数进行预测

java - 从一个类到另一个类获取数组长度

python - 创建文件并在 View 中将其返回给 Django