Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/303.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python Numpy使用交错连接阵列_Python_Arrays_Numpy - Fatal编程技术网

Python Numpy使用交错连接阵列

Python Numpy使用交错连接阵列,python,arrays,numpy,Python,Arrays,Numpy,我有4个数组,我想通过交错将它们连接成一个数组。我该怎么做 >>> import numpy as np >>> a = np.tile(0,(5,2)) >>> b = np.tile(1,(5,2)) >>> c = np.tile(2,(5,2)) >>> d = np.tile(3,(5,2)) >>> e = np.concatenate((a,b,c,d),axis=1) &g

我有4个数组,我想通过交错将它们连接成一个数组。我该怎么做

>>> import numpy as np
>>> a = np.tile(0,(5,2))
>>> b = np.tile(1,(5,2))
>>> c = np.tile(2,(5,2))
>>> d = np.tile(3,(5,2))
>>> e = np.concatenate((a,b,c,d),axis=1)
>>> e
    array([[0, 0, 1, 1, 2, 2, 3, 3],
           [0, 0, 1, 1, 2, 2, 3, 3],
           [0, 0, 1, 1, 2, 2, 3, 3],
           [0, 0, 1, 1, 2, 2, 3, 3],
           [0, 0, 1, 1, 2, 2, 3, 3]])
这只提供了连接

但是,我期望的_输出是:

>>> desired_output
    array([[0, 1, 2, 3, 0, 1, 2, 3],
           [0, 1, 2, 3, 0, 1, 2, 3],
           [0, 1, 2, 3, 0, 1, 2, 3],
           [0, 1, 2, 3, 0, 1, 2, 3],
           [0, 1, 2, 3, 0, 1, 2, 3]])
我的意思是我知道我可以使用以下方法从e中选择交错列:

>>> f = e[:, ::2]
>>> array([[0, 1, 2, 3],
           [0, 1, 2, 3],
           [0, 1, 2, 3],
           [0, 1, 2, 3],
           [0, 1, 2, 3]])
但是我如何制作一个大数组呢?

使用或沿最后一个轴堆叠,从而生成一个
3D
数组,然后重新塑造为
2D
-

np.dstack([a,b,c,d]).reshape(a.shape[0],-1)
np.stack([a,b,c,d],axis=2).reshape(a.shape[0],-1)

好极了!!谢谢你,伙计!那真的很快。你这样做是为了谋生还是干什么@bFig8;)@bFig8如果你想问这个问题,这里有一些帮助。