If I call this function on my dataset:
def reconstruct_flight(data, sequence_lenght, flight_len, param_len):
stack_factor = int(flight_len/sequence_lenght)
data_reconstructed = []
for i in range(0, len(data_clean), stack_factor):
if i<len(data_clean):
data_reconstructed.append(
data[i:i stack_factor].reshape(
[flight_len, param_len])
)
return np.array(data_reconstructed)
I get the following error:
ValueError: cannot reshape array of size 0 into shape (1500,77)
But if I run the for
loop in the console without passing it as a function:
data_reconstructed = []
for i in range(0, len(data_clean), stack_factor):
if i<len(data_clean):
data_reconstructed.append(
data[i:i stack_factor].reshape(
[flight_len, param_len])
)
It works as expected. Why is that ?
CodePudding user response:
When reshaping, if you are keeping the same data contiguity and just reshaping the box, you can reshape your data with
data_reconstructed = data_clean.reshape((10,1500,77))
if you are changing the contiguity from one axis to another, you will need to add a permutation of the axes beforehand https://numpy.org/doc/stable/reference/generated/numpy.transpose.html