[英]Is there a way to get a 2d slice of 3d matrix (nested lists)
I'm have some data that is being stored in a 3x3x3 nested list and I want to get 2d layers form that list. 我有一些数据存储在3x3x3嵌套列表中,我想从该列表中获取2D图层。
for example I want to do something like a[:, :,2], a[0,:,:] or a[:,1,:] on the following list: 例如,我想在以下列表中执行类似a [:,:,2],a [0,:,:]或a [:,1 ,:]的操作:
a=[
[
[(0, 0, 0), (0, 0, 1), (0, 0, 2)],
[(0, 1, 0), (0, 1, 1), (0, 1, 2)],
[(0, 2, 0), (0, 2, 1), (0, 2, 2)],
],
[
[(1, 0, 0), (1, 0, 1), (1, 0, 2)],
[(1, 1, 0), (1, 1, 1), (1, 1, 2)],
[(1, 2, 0), (1, 2, 1), (1, 2, 2)],
],
[
[(2, 0, 0), (2, 0, 1), (2, 0, 2)],
[(2, 1, 0), (2, 1, 1), (2, 1, 2)],
[(2, 2, 0), (2, 2, 1), (2, 2, 2)],
],]
to get: 要得到:
[
[(0, 1, 0), (0, 1, 1), (0, 1, 2)],
[(1, 1, 0), (1, 1, 1), (1, 1, 2)],
[(2, 1, 0), (2, 1, 1), (2, 1, 2)],]
I tried that but doing a[:][1][:] does nothing to the list so I just get a[1] which looks like this: 我试过了,但是执行a [:] [1] [:]对列表没有任何作用,所以我只得到看起来像这样的a [1]:
[
[(1, 0, 0), (1, 0, 1), (1, 0, 2)],
[(1, 1, 0), (1, 1, 1), (1, 1, 2)],
[(1, 2, 0), (1, 2, 1), (1, 2, 2)],]
I don't think I can use numpy because I'm using jython which doesn't support libraries implemented in c. 我不认为我可以使用numpy,因为我使用的jython不支持用c实现的库。
Can you help me find a way to do it nicely (or find a library like numpy that works on jython)? 您能帮我找到一种做得很好的方法(或找到像numpy这样可在jython上运行的库)吗?
这将收集每个子矩阵的中间行:
[x[1] for x in a]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.