我有一个四维阵列:array = np.random.rand(3432,1,30,512)
numpy的插入2D阵列到4D构造
我也有5具有形状套2D阵列(30,512)
我要插入这些成沿轴1的4D结构,使得我的最终形状是(3432,6,30,512)
(5个新阵列+原始1)。我需要为每个3432元素迭代插入此集合
最有效的方法是什么?
我试过将2D重塑成4D,然后沿着轴1插入。我期望轴1永远不会超过6的大小,但2D数组只是不断增加,而不是每组3432个元素。我想我的问题就出在不完全了解obj
参数有关的insert
方法:
all_data = np.reshape(all_data, (-1, 1, 30, 512))
for i in range(all_data.shape[0]):
num_band = 1
for band in range(5):
temp_trial = np.zeros((30, 512)) # Just an example. values arent actually 0
temp_trial = np.reshape(temp_trial, (1,1,30,512))
all_data = np.insert(all_data, num_band, temp_trial, 1)
num_band += 1
“insert”并不意味着迭代工作。确保您首先了解文档示例。 – hpaulj