简体   繁体   English

通过从每个数组中选取 1 列来堆叠多个二维数组

[英]Stacking multiple 2d arrays by picking 1 column from each of the arrays

I have 3 numpy arrays of dimensions 20x308 each.我有 3 个 numpy 数组,每个数组的尺寸为 20x308。 I want to stack them so that i have the first column from 1st array, 1st column from 2nd array, 1st from 3rd and then 2nd from each and so on so that i will end up with 20x924 array.我想堆叠它们,以便我拥有第一个数组的第一列,第二个数组的第一列,第三个数组的第一个,然后每个数组的第二个等等,这样我最终会得到 20x924 数组。 I have tried by looking at np.column_stack but that won't work.我试过查看 np.column_stack 但这不起作用。 Thank You.谢谢你。

I have found a solution now, by using dstack and reshape.我现在通过使用 dstack 和 reshape 找到了解决方案。

    a = np.ones((2,3))
    b = np.zeros_like(a)
    d = [[1,3,5], [2,5,9]]
    c = np.dstack([a, b,d]).reshape(2,9)

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

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