Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/365.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 串联后数组大小减小_Python_Numpy - Fatal编程技术网

Python 串联后数组大小减小

Python 串联后数组大小减小,python,numpy,Python,Numpy,我有两个.npz文件,我想连接(也尝试了hstack),但连接后小于两个文件的总和。我只是想知道,它是否会减少连接后的大小。以下代码供您参考 from numpy import load import numpy as np en_1 = load('encoded_1.npz') en_2 = load('encoded_2.npz') en_11 = en_1['arr_0'].reshape(1, -1) en_22 = en_1['arr_0'].reshape(1, -1) pr

我有两个.npz文件,我想连接(也尝试了hstack),但连接后小于两个文件的总和。我只是想知道,它是否会减少连接后的大小。以下代码供您参考

from numpy import load
import numpy as np

en_1 = load('encoded_1.npz')
en_2 = load('encoded_2.npz')

en_11 = en_1['arr_0'].reshape(1, -1)
en_22 = en_1['arr_0'].reshape(1, -1)

print("Size of en_1 :"+en_1['arr_0'].shape)
print("Size of en_2 :"+en_2['arr_0'].shape)

#mid = np.hstack((en_11,en_22))
mid = np.concatenate((en_11, en_22),axis=1)

print("Size after concatenation :"+mid.shape)
这是输出

Output
Size of en_1 : (68226020,)
Size of en_2 : (136340912,)
Size after concatenation : (1, 136452040)
正在查找连接大小:(1204566932)

正在寻求帮助。

您可以尝试以下方法:

en_11 = en_11.reshape(1,en_11.shape[0])
en_22 = en_22.reshape(1,en_22.shape[0])
然后:

mid = np.concatenate((en_11, en_22),axis=1)
您可以尝试以下方法:

en_11 = en_11.reshape(1,en_11.shape[0])
en_22 = en_22.reshape(1,en_22.shape[0])
然后:

mid = np.concatenate((en_11, en_22),axis=1)
不应该

en_22 = en_1['arr_0'].reshape(1, -1)

en_11(68226020)的两倍大小等于(136452040).

不应该

en_22 = en_1['arr_0'].reshape(1, -1)


en_11(68226020)大小的两倍等于(136452040).

我希望它位于轴=1上。如果我取轴=0,那么它取第一个数组的大小(268226020)。你想要达到的目标形状是什么?我想要它取轴=1。如果我取axis=0,那么它取第一个数组的大小(268226020)。您试图实现的目标形状是什么?