在一个三维数组numpy的结合3阵列 [英] Combining 3 arrays in one 3D array in numpy
本文介绍了在一个三维数组numpy的结合3阵列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个关于在numpy的阵列来一个很基本的问题,但我不能找到一个快速的方法来做到这一点。我有三个二维数组A,B,C具有相同的尺寸。我想在一个三维阵列(D),其中每个元素是一个数组转换这些
I have a very basic question regarding to arrays in numpy, but I cannot find a fast way to do it. I have three 2D arrays A,B,C with the same dimensions. I want to convert these in one 3D array (D) where each element is an array
D[column][row] = [A[column][row] B[column][row] c[column][row]]
什么是做到这一点的最好方法是什么?
What is the best way to do it?
推荐答案
您可以使用 numpy.dstack :
>>> import numpy as np
>>> a = np.random.random((11, 13))
>>> b = np.random.random((11, 13))
>>> c = np.random.random((11, 13))
>>>
>>> d = np.dstack([a,b,c])
>>>
>>> d.shape
(11, 13, 3)
>>>
>>> a[1,5], b[1,5], c[1,5]
(0.92522736614222956, 0.64294050918477097, 0.28230222357027068)
>>> d[1,5]
array([ 0.92522737, 0.64294051, 0.28230222])
这篇关于在一个三维数组numpy的结合3阵列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文