Python ValueError:使用序列设置数组元素。-特征工程

Python ValueError:使用序列设置数组元素。-特征工程,python,arrays,types,feature-extraction,feature-engineering,Python,Arrays,Types,Feature Extraction,Feature Engineering,我在特征转换、模型拟合等方面有问题。我有一个数据集,看起来如下: >>>ar 如您所见,每个数组元素由另一个带有浮点元素的数组组成。整个阵列的形状是(5252,5)。我想用它来处理数据,例如拟合模型,连接到另一个数组,但当我尝试时: def calculate_statistics(list_values): n5 = np.nanpercentile(list_values, 5) n25 = np.nanpercentile(list_values, 25

我在特征转换、模型拟合等方面有问题。我有一个数据集,看起来如下:

>>>ar
如您所见,每个数组元素由另一个带有浮点元素的数组组成。整个阵列的形状是(5252,5)。我想用它来处理数据,例如拟合模型,连接到另一个数组,但当我尝试时:

def calculate_statistics(list_values):
    n5 = np.nanpercentile(list_values, 5)
    n25 = np.nanpercentile(list_values, 25)
    n75 = np.nanpercentile(list_values, 75)
    n95 = np.nanpercentile(list_values, 95)
    median = np.nanpercentile(list_values, 50)
    mean = np.nanmean(list_values)
    std = np.nanstd(list_values)
    var = np.nanvar(list_values)
    rms = np.nanmean(np.sqrt(list_values**2))
    return [n5, n25, n75, n95, median, mean, std, var, rms]

def calculate_crossings(list_values):
    zero_crossing_indices = np.nonzero(np.diff(np.array(list_values) > 0))[0]
    no_zero_crossings = len(zero_crossing_indices)
    mean_crossing_indices = np.nonzero(np.diff(np.array(list_values) > np.nanmean(list_values)))[0]
    no_mean_crossings = len(mean_crossing_indices)
    return [no_zero_crossings, no_mean_crossings]

def get_features(list_values):
    #entropy = calculate_entropy(list_values)
    crossings = calculate_crossings(list_values)
    statistics = calculate_statistics(list_values)
    return statistics +crossings

def convert(array1, array2):
    for x in range (0, array1.shape[0]):
        for y in range (0, array2.shape[1]):
            array2[x][y] = get_features(array1[x][y])

ar_ed = np.zeros((5252, 5), dtype=float)

convert(ar, ar_ed)
“ar”是精心设计的阵列,ar_ed是目标阵列,应该可以适合模型。我有一个错误:

ValueError: setting an array element with a sequence. 
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
TypeError: float() argument must be a string or a number, not 'list'

The above exception was the direct cause of the following exception:

ValueError                                Traceback (most recent call last)
<ipython-input-61-23e774aa76cb> in <module>
----> 1 convert(ar, ar_ed)

<ipython-input-59-661bbbd7b7c2> in convert(array1, array2)
      2     for x in range (0, 5):
      3         for y in range (0, 5):
----> 4             array2[x][y] = get_features(array1[x][y])

ValueError: setting an array element with a sequence.
ValueError:设置带有序列的数组元素。
---------------------------------------------------------------------------
TypeError回溯(最近一次调用上次)
TypeError:float()参数必须是字符串或数字,而不是“list”
上述异常是以下异常的直接原因:
ValueError回溯(最近一次调用上次)
在里面
---->1转换(应收账款、应收账款)
转换中(阵列1、阵列2)
2表示范围(0,5)内的x:
在范围(0,5)内y为3:
---->4 array2[x][y]=获取功能(array1[x][y])
ValueError:使用序列设置数组元素。

我怎样才能修复它?

好的,我知道我做错了什么。在所有操作之前,我再次将数据集转换为numpy数组,这样函数和其他函数就可以处理数据,因为它们不是列表

ValueError: setting an array element with a sequence. 
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
TypeError: float() argument must be a string or a number, not 'list'

The above exception was the direct cause of the following exception:

ValueError                                Traceback (most recent call last)
<ipython-input-61-23e774aa76cb> in <module>
----> 1 convert(ar, ar_ed)

<ipython-input-59-661bbbd7b7c2> in convert(array1, array2)
      2     for x in range (0, 5):
      3         for y in range (0, 5):
----> 4             array2[x][y] = get_features(array1[x][y])

ValueError: setting an array element with a sequence.