ValueError: cannot reshape array of size 0

ValueError: cannot reshape array of size 0

如果我在我的数据集上调用这个函数:

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)

我收到以下错误:

ValueError: cannot reshape array of size 0 into shape (1500,77)

但是如果我 运行 在控制台中 for 循环而不将其作为函数传递:

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])
                )

它按预期工作。这是为什么?

重塑时,如果您保持相同的数据连续性并且只是重塑框,则可以使用

重塑数据
data_reconstructed = data_clean.reshape((10,1500,77))

如果要将连续性从一个轴更改为另一个轴,则需要事先添加轴排列https://numpy.org/doc/stable/reference/generated/numpy.transpose.html