我有一个具有不同形状的numpy数组列表。我尝试将此列表转换为numpy数组,以便为Keras创建批处理示例。在输出中我想要一个带有形状的数组(batch_size,?,20),其中'?'是可变维度。我试试这个:
a = np.random.random((5,20))
b = np.random.random((2,20))
c = np.random.random((7,20))
d = [a,b,c]
np.array(d).shape
> (3,)
当我将此批次发送给Keras时,我遇到以下问题:
ValueError: Error when checking input: expected Input_Dim to have 3 dimensions, but got array with shape (3, 1)
也许这个简单的例子可以帮助:
import numpy as np
a = np.random.random((5,20))
b = np.random.random((2,20))
c = np.random.random((7,20))
d = np.array([a,b,c])
print(d.shape) # (3,)
d = d[np.newaxis]
print(d.shape) # (1, 3)