最佳答案
看起来我有一个 NumPy 数组列表(type() = np.ndarray
)格式的数据:
[array([[ 0.00353654]]), array([[ 0.00353654]]), array([[ 0.00353654]]),
array([[ 0.00353654]]), array([[ 0.00353654]]), array([[ 0.00353654]]),
array([[ 0.00353654]]), array([[ 0.00353654]]), array([[ 0.00353654]]),
array([[ 0.00353654]]), array([[ 0.00353654]]), array([[ 0.00353654]]),
array([[ 0.00353654]])]
我试图把它放进一个多配合函数中:
m1 = np.polyfit(x, y, deg=2)
但是,它返回错误: TypeError: expected 1D vector for x
我假设我需要将我的数据扁平化,例如:
[0.00353654, 0.00353654, 0.00353654, 0.00353654, 0.00353654, 0.00353654 ...]
我尝试过一种列表内涵,这种方法通常适用于列表,但这种方法并不奏效:
[val for sublist in risks for val in sublist]
最好的方法是什么?