Iは、4D配列を有する:array = np.random.rand(3432,1,30,512)
は、4D構造に2次元配列を挿入numpyの
私はまた私がその軸1に沿って、4D構造にこれらを挿入する(30,512)
形状の2次元配列の5セットを持っているが私の最終的な形は(3432,6,30,512)
(5つの新しい配列+元の1)です。この3432個の要素ごとにこのセットを繰り返し挿入する必要があります
これを行う最も効果的な方法は何ですか?
私は、2Dから4Dへの再成形を試みてから、軸1に沿って挿入しました。私は、軸1が6のサイズを決して超えないことを期待していますが、2D配列は、 3432要素。
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