python - python中的矩阵镜像

标签 python arrays python-3.x numpy matrix

我有一个数字矩阵:

[[a, b, c] 
 [d, e, f] 
 [g, h, i]]

我想被相应地镜像:

[[g, h, i]
 [d, e, f]
 [a, b, c] 
 [d, e, f] 
 [g, h, i]]

然后再次产生:

[[i, h, g, h, i]
 [f, e, d, e, f]
 [c, b, a, b, c] 
 [f, e, d, e, f] 
 [i, h, g, h, i]]

我想坚持使用像 numpy 这样的基本 Python 包。在此先感谢您的帮助!!

最佳答案

这可以在纯 python 中使用一个简单的辅助函数来完成:

def mirror(seq):
    output = list(seq[::-1])
    output.extend(seq[1:])
    return output

inputs = [
   ['a', 'b', 'c'],
   ['d', 'e', 'f'],
   ['g', 'h', 'i'],
]
print(mirror([mirror(sublist) for sublist in inputs]))

显然,一旦创建了镜像列表,您就可以使用它来创建一个 numpy 数组或其他...

关于python - python中的矩阵镜像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40837224/

相关文章:

javascript - Javascript 中的 Array() 和 [] 有什么区别,为什么我要使用一个而不是另一个?

javascript - HTML JS 组装数组名称工作正常但随后打印为 "string"而不是实际作业

java - 以交替方式合并两个数组

python-3.x - 如何为python3安装omniORB?

python - Pyspark Dataframe 插补——根据指定条件用列平均值替换未知值和缺失值

python - 匹配交替的数字和字符

python - 如何将 pandas loc 索引器转换为字符串?

python - 当电脑关闭时触发一个函数 - tkinter

Python 多处理/队列与cherrypy

python - 如何有效地提取视频的特定部分(Python/FFmpeg)?