Be careful when reshaping. Even if it works, the arrangement of elements may not be what you want.
Start with a simple array that we can visualize:
In [805]: x = np.arange(24).reshape(3,2,4)
In [806]: x
Out[806]:
array([[[ 0, 1, 2, 3],
[ 4, 5, 6, 7]],
[[ 8, 9, 10, 11],
[12, 13, 14, 15]],
[[16, 17, 18, 19],
[20, 21, 22, 23]]])
reshape to (-1,2,1) - but lets drop the last 1 for a more compact display:
In [807]: x.reshape(-1,2)
Out[807]:
array([[ 0, 1],
[ 2, 3],
[ 4, 5],
[ 6, 7],
[ 8, 9],
[10, 11],
[12, 13],
[14, 15],
[16, 17],
[18, 19],
[20, 21],
[22, 23]])
Notice how the original [0,1,2,3] line gets split into 2 lines.
Another way of redistributing the last dimension of size 4 is:
In [808]: np.vstack([x[...,i] for i in range(4)])
Out[808]:
array([[ 0, 4],
[ 8, 12],
[16, 20],
[ 1, 5],
[ 9, 13],
[17, 21],
[ 2, 6],
[10, 14],
[18, 22],
[ 3, 7],
[11, 15],
[19, 23]])
That may be clearer if we used np.stack and got (4,3,2) shape
array([[[ 0, 4],
[ 8, 12],
[16, 20]],
....
x.transpose(2,0,1) produces the same thing.
reshape preserves the ravelled/flattened order of elements. Transpose changes it.
In [812]: x.transpose(2,0,1).ravel()
Out[812]:
array([ 0, 4, 8, 12, 16, 20, 1, 5, 9, 13, 17, 21, 2, 6, 10, 14,...])
In [813]: x.reshape(-2,2).ravel()
Out[813]:
array([ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, ...])
[i[0] for i in train]?trainis, so no idea.