Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/300.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_Numpy - Fatal编程技术网

Python 如何使用numpy水平连接图像?

Python 如何使用numpy水平连接图像?,python,numpy,Python,Numpy,我试图用MNIST图像生成一个合成序列。每个图像被展平784。当我选择其中五个时,我的数据是shape(5784)。 我想水平连接其中的5个,使我的最终图像具有形状(28,5*28)。我怎样才能做到这一点 我尝试了np.Reforme,但我能达到的最好效果是垂直拼接。为了演示,我们想水平拼接三个图像,它们是4x4,以16个元素的形式存储: a = np.arange(16) b = np.arange(16,32) c = np.arange(32,48) images = np.array(

我试图用MNIST图像生成一个合成序列。每个图像被展平784。当我选择其中五个时,我的数据是shape(5784)。 我想水平连接其中的5个,使我的最终图像具有形状(28,5*28)。我怎样才能做到这一点


我尝试了np.Reforme,但我能达到的最好效果是垂直拼接。

为了演示,我们想水平拼接三个图像,它们是4x4,以16个元素的形式存储:

a = np.arange(16)
b = np.arange(16,32)
c = np.arange(32,48)

images = np.array([a,b,c]) # 3x16
这只是为了准备样本数据。现在重塑并连接:

np.hstack(images.reshape(3,4,4))
结果是:

array([[ 0,  1,  2,  3, 16, 17, 18, 19, 32, 33, 34, 35],
       [ 4,  5,  6,  7, 20, 21, 22, 23, 36, 37, 38, 39],
       [ 8,  9, 10, 11, 24, 25, 26, 27, 40, 41, 42, 43],
       [12, 13, 14, 15, 28, 29, 30, 31, 44, 45, 46, 47]])
在您最初的情况下,表达式为:

np.hstack(stuff.reshape(5,28,28))

实际上,形状是(28140)。

为了演示,我们想水平连接三个图像,它们是4x4,以16个元素的形式存储:

a = np.arange(16)
b = np.arange(16,32)
c = np.arange(32,48)

images = np.array([a,b,c]) # 3x16
这只是为了准备样本数据。现在重塑并连接:

np.hstack(images.reshape(3,4,4))
结果是:

array([[ 0,  1,  2,  3, 16, 17, 18, 19, 32, 33, 34, 35],
       [ 4,  5,  6,  7, 20, 21, 22, 23, 36, 37, 38, 39],
       [ 8,  9, 10, 11, 24, 25, 26, 27, 40, 41, 42, 43],
       [12, 13, 14, 15, 28, 29, 30, 31, 44, 45, 46, 47]])
在您最初的情况下,表达式为:

np.hstack(stuff.reshape(5,28,28))
事实上,形状是(28140)