I am running into an understanding problem of numpy arrays. I have a dataset which looks like this when read:
[
[ F0, F1, F2, F3 ... F22],
[ G0, G1, G2, G3 ... G22],
[ H0, H1, H2, H3 ... H22],
[ I0, I1, I2, I3 ... I22],
[ J0, J1, J2, J3 ... J22]
]
And I want to transform those in "packs of three":
[
[
[ F0, F1, F2, F3 ... F22],
[ G0, G1, G2, G3 ... G22],
[ H0, H1, H2, H3 ... H22]
],
[
[ G0, G1, G2, G3 ... G22],
[ H0, H1, H2, H3 ... H22],
[ I0, I1, I2, I3 ... I22]
]
...
]
So far I have wrote this code:
data = loadtxt('./training_data/set_0.csv', delimiter=';')
batch_size=3
features=17
labels=6
trainX = np.empty((0,batch_size, features), float)
for i in range(0, len(data)-batch_size):
row_X = data[i:i+batch_size,0:features]
trainX = np.append(trainX, row_X)
print(trainX[0])
Logging the shape of row_X gives me (3,17) just as I wanted.
But the trainX variable seems to contain the flat combination of those arrays, I would have expected the shape of trainX[0] to be (batch_size,features).
np.appenddocs: Ifaxisis not given, botharrandvaluesare flattened before use.? If you do includeaxisthen the number of dimensions must match (since it just callsnp.concatenate). Read and reread the docs!