[SciPy-dev] pbm in numpy.linalg.polyfit and nupy.linalg polyfit

Julien Le Sommer lesommer@hmg.inpg...
Wed Mar 12 22:58:39 CDT 2008


Hi,

I just want to mention  a possible bug in numpy/lib/polynomial.py
with numpy version > 1.0.4 (with python2.4).

the modification introduced with revision 3338 of numpy by charris,
(see http://www.scipy.org/scipy/numpy/log/trunk/numpy/lib/polynomial.py)
has broken the possibility to use polyfit with two-dimensional arrays.

IPython gives the following message :
------------------------------------------------------------------------------------------
    308     # scale returned coefficients
    309     if scale != 0 :
--> 310         c /= vander([scale], order)[0]
    311
    312     if full :

ValueError: shape mismatch: objects cannot be broadcast to a single shape
--------------------------------------------------------------------------------------------

with the following script :
--------------------------------------------------------------------------------------------
import numpy
from numpy.random import *
from numpy import linalg

#- create some arrays :
n = 100
r = 0.5
a = 1.4

# 1D vector
T = numpy.array(xrange(n),dtype=numpy.float32)*2/(n-1) -1.
X = a*T +r*(rand(n)-0.5)

# (n * 2) array
aa = numpy.array([[0.7,1.2]])
rr = numpy.array([[0.4,0.6]])
TT = T.reshape((n,1))*numpy.ones((n,2))
XX = aa*TT +rr*(randn(n,2)-0.5)

# (n * 3) array
aaa = numpy.array([[0.7,1.2,1.]])
rrr = numpy.array([[0.4,0.6,0.2]])
TTT = T.reshape((n,1))*numpy.ones((n,3))
XXX = aaa*TTT +rrr*(randn(n,3)-0.5)


#- try numpy.polyfit


# works ok
(ar,br) = numpy.polyfit(T,X,1)

# works ok
(ar,br) = numpy.polyfit(T,XX,1)

# fails
(ar,br) = numpy.polyfit(T,XXX,1)


-- 
   Julien Le Sommer, LEGI/MEOM,
   BP53, 38041 Grenoble cedex 9, France
   Tel : +33 4 76 82 50 65
   Fax : +33 4 76 82 52 71
   http://www.legi.hmg.inpg.fr/~lesommer/
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://projects.scipy.org/pipermail/scipy-dev/attachments/20080313/03c079e7/attachment.html 


More information about the Scipy-dev mailing list