It appears that I have data in the format of a list of NumPy arrays (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]])]
I am trying to put this into a polyfit function:
m1 = np.polyfit(x, y, deg=2)
However, it returns the error: TypeError: expected 1D vector for x
I assume I need to flatten my data into something like:
[0.00353654, 0.00353654, 0.00353654, 0.00353654, 0.00353654, 0.00353654 ...]
I have tried a list comprehension which usually works on lists of lists, but this as expected has not worked:
[val for sublist in risks for val in sublist]
What would be the best way to do this?
See Question&Answers more detail:os