简体   繁体   English

刺伤一个3d阵列

[英]Stab a 3d array

I have a 3d array from which I am trying to a list of stabs. 我有一个3d数组,我正在尝试一个stab列表。 Put another way, given the array: 换句话说,给定数组:

t = np.array([[[1,2],[3,4]],[[5,6],[7,8]],[[9,10],[11,12]]])

array([[[ 1,  2],
      [ 3,  4]],

     [[ 5,  6],
      [ 7,  8]],

     [[ 9, 10],
      [11, 12]]])

I am trying to retrieve: 我试图检索:

array([[ 1,  5,  9],
       [ 2,  6, 10],
       [ 3,  7, 11],
       [ 4,  8, 12]])

np.ndarray.reshape seems to reorganise elements in a sequential order that precludes stabs. np.ndarray.reshape似乎按顺序排列元素,排除了刺伤。

numpy.lib.stride_tricks.as_strided might work, but I have yet to find the correct combination of values. numpy.lib.stride_tricks.as_strided可能有效,但我还没有找到正确的值组合。

Transpose then reshape: 转置然后重塑:

>>> t.transpose(1, 2, 0).reshape(4, 3)
array([[ 1,  5,  9],
       [ 2,  6, 10],
       [ 3,  7, 11],
       [ 4,  8, 12]])

Edit: alternatively, you can reshape then transpose: 编辑:或者,你可以重塑然后转置:

>>> t.reshape(3, 4).T
array([[ 1,  5,  9],
       [ 2,  6, 10],
       [ 3,  7, 11],
       [ 4,  8, 12]])

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM