我有一个数字矩阵:
[[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/