[Numpy-discussion] Runtime error in numpy.polyfit

William Carithers wccarithers at lbl.gov
Wed May 19 15:51:36 EDT 2010


Thanks David and Josef. Replies interspersed below.


On 5/19/10 12:24 PM, "josef.pktd at gmail.com" <josef.pktd at gmail.com> wrote:

> On Wed, May 19, 2010 at 3:18 PM, David Goldsmith
> <d.l.goldsmith at gmail.com> wrote:
>> Charles H.: is this happening because he's calling the old version of
>> polyfit?
>> 
>> William: try using numpy.polynomial.polyfit instead, see if that works.

It says  ypoly = n.polynomial.polyfit(yvalues, avalues, 2)
AttributeError: 'module' object has no attribute 'polynomial'

Is this because I'm using a relatively old (numpy-1.2.1) version?
>> 
>> DG
>> 
>> On Wed, May 19, 2010 at 11:03 AM, William Carithers <wccarithers at lbl.gov>
>> wrote:
>>> 
>>> I'm trying to do a simple 2nd degree polynomial fit to two arrays of 5
>>> entries. I get a runtime error:
>>> RuntimeError: more argument specifiers than keyword list entries
>>> (remaining
>>> format:'|:calc_lwork.gelss')  in the lstsq module inside numpy.polyfit.
>>> 
>>> Here's the code snippet:
>>> def findPeak(self, ydex, xdex):
>>>        # take a vertical slice
>>>        vslice = []
>>>        for i in range(-1,10,1) :
>>>            vslice.append(arcImage[ydex+i][xdex])
>>>        vdex = n.where(vslice == max(vslice))
>>>        ymax = ydex -1 + vdex[0][0]
>>>        # approximate gaussian fit by parabolic fit to logs
>>>        yvalues = n.array([ymax-2, ymax-1, ymax, ymax+1, ymax+2])
>>> 
>>> 
>>> svalues=n.array([arcImage[ymax-2][xdex],arcImage[ymax-1][xdex],arcImage[ymax
>>> ][xdex],arcImage[ymax+1][xdex], arcImage[ymax+2][xdex]])
>>>        avalues = n.log(svalues)
>>>        ypoly = n.polyfit(yvalues, avalues, 2)
>>> 
>>> And the traceback:
>>> File "/Users/williamcarithers/BOSS/src/calibrationModel.py", line 345, in
>>> findPeak
>>>    ypoly = n.polyfit(yvalues, avalues, 2)
>>>  File
>>> 
>>> "/System/Library/Frameworks/Python.framework/Versions/2.6/Extras/lib/python/
>>> numpy/lib/polynomial.py", line 503, in polyfit
>>>    c, resids, rank, s = _lstsq(v, y, rcond)
>>>  File
>>> 
>>> "/System/Library/Frameworks/Python.framework/Versions/2.6/Extras/lib/python/
>>> numpy/lib/polynomial.py", line 46, in _lstsq
>>>    return lstsq(X, y, rcond)
>>>  File
>>> 
>>> "/Library/Python/2.6/site-packages/scipy-0.7.1-py2.6-macosx-10.6-universal.e
>>> gg/scipy/linalg/basic.py", line 545, in lstsq
>>>    lwork = calc_lwork.gelss(gelss.prefix,m,n,nrhs)[1]
>>> RuntimeError: more argument specifiers than keyword list entries
>>> (remaining
>>> format:'|:calc_lwork.gelss')
>>> 
>>> This is such a simple application of polyfit and the error occurs in the
>>> guts of lstsq, so I'm completely stumped. Any help would be greatly
>>> appreciated.
> 
> which version of numpy and the arguments to polyfit would be useful
> information,e.g.
> 
> print repr(yvalues)
> print repr(avalues)
> 
> before the call to polyfit

Hi Josef,

I'm using numpy-1.2.1

Here are the arrays
array([ 864.,  865.,  866.,  867.,  868.])
array([ 5.24860191,  6.0217514 ,  6.11434555,  6.09198856,  5.73753977],
dtype=float32)

thanks
> 
> Josef
> 
> 
>>> 
>>> Thanks,
>>> Bill Carithers
>>> 
>>> 
>>> _______________________________________________
>>> NumPy-Discussion mailing list
>>> NumPy-Discussion at scipy.org
>>> http://mail.scipy.org/mailman/listinfo/numpy-discussion
>> 
>> 
>> 
>> --
>> Mathematician: noun, someone who disavows certainty when their uncertainty
>> set is non-empty, even if that set has measure zero.
>> 
>> Hope: noun, that delusive spirit which escaped Pandora's jar and, with her
>> lies, prevents mankind from committing a general suicide.  (As interpreted
>> by Robert Graves)
>> 
>> _______________________________________________
>> NumPy-Discussion mailing list
>> NumPy-Discussion at scipy.org
>> http://mail.scipy.org/mailman/listinfo/numpy-discussion
>> 
>> 
> _______________________________________________
> NumPy-Discussion mailing list
> NumPy-Discussion at scipy.org
> http://mail.scipy.org/mailman/listinfo/numpy-discussion





More information about the NumPy-Discussion mailing list