[Numpy-discussion] nan result from np.linalg.lstsq()
Larry Paltrow
larry.paltrow@gmail....
Mon Oct 29 03:40:28 CDT 2012
I'm having some trouble using the linalg.lstsq() function with certain data
and trying to understand why. It's always returning nans when I feed it
this numpy array of float64 data:
data = df.close.values #coming from a pandas dataframe
type(data)
>>> numpy.ndarray
data.dtype
>>> dtype('float64')
data
>>> array([ 1.31570348, 1.31565421, 1.3157375 , ..., 1.32175 ,
1.32180441, 1.321775 ])
xi = np.arange(0,len(data))
A = np.vstack([xi, np.ones(len(xi))]).T A
>>> array([[ 0.00000000e+00, 1.00000000e+00],
[ 1.00000000e+00, 1.00000000e+00],
[ 2.00000000e+00, 1.00000000e+00],
...,
[ 2.87800000e+03, 1.00000000e+00],
[ 2.87900000e+03, 1.00000000e+00],
[ 2.88000000e+03, 1.00000000e+00]])
m, c = np.linalg.lstsq(A, data)[0]
m, c
>>> (nan, nan)
oy, do not understand. Does anyone else know why?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.scipy.org/pipermail/numpy-discussion/attachments/20121029/956dfac0/attachment.html
More information about the NumPy-Discussion
mailing list