[Numpy-discussion] Question about nump.ma.polyfit

Eric Firing efiring at hawaii.edu
Tue Dec 15 11:34:44 EST 2015


On 2015/12/14 6:39 PM, Samuel Dupree wrote:
> I'm running Python 2.7.11 from the Anaconda distribution (version 2.4.1)
> on a MacBook Pro running Mac OS X version 10.11.2 (El Capitan)
>
> I'm attempting to use numpy.ma.polyfit to perform a linear least square
> fit on some data I have. I'm running NumPy version 1.10.1. I've observed
> that in executing either numpy.polyfit or numpy.ma.polyfit I get the
> following traceback:
>
> /Users/user/anaconda/lib/python2.7/site-packages/numpy/lib/polynomial.py:594:
> RankWarning: Polyfit may be poorly conditioned
>    warnings.warn(msg, RankWarning)
> Traceback (most recent call last):
>    File "ComputeEnergy.py", line 132, in <module>
>      coeffs, covar = np.ma.polyfit( xfit, yfit, fit_degree,
> rcond=rcondv, cov=True )
>    File
> "/Users/user/anaconda/lib/python2.7/site-packages/numpy/ma/extras.py",
> line 1951, in polyfit
>      return np.polyfit(x, y, deg, rcond, full, w, cov)
>    File
> "/Users/user/anaconda/lib/python2.7/site-packages/numpy/lib/polynomial.py",
> line 607, in polyfit
>      return c, Vbase * fac
> ValueError: operands could not be broadcast together with shapes (6,6) (0,)
>
>
> I've attached a stripped down version of the Python program I'm running.

Sam,

That is not stripped down very far; it's still not something someone on 
the list can run.

>
> Any suggestions?

Use debugging techniques to figure out what is going on inside your 
script.  In particular, what are the arguments that polyfit is choking 
on?  I would run the script in ipython and use the %debug magic to drop 
into the debugger when it fails.  Then use "up" to move up the stack 
until you get to the line calling polyfit, and then use the print 
function to print each of the arguments.  Chances are, either they will 
not be what you expect them to be, or they will, but you will find a 
logical inconsistency among them.  It looks like you are using Spyder, 
presumably with the ipython console, so run your script, then when it 
fails type "%debug" in the ipython console window and you will be 
dropped into the standard pdb debugger.

Eric

>
> Sam Dupree.
>
>
> _______________________________________________
> NumPy-Discussion mailing list
> NumPy-Discussion at scipy.org
> https://mail.scipy.org/mailman/listinfo/numpy-discussion
>




More information about the NumPy-Discussion mailing list