[SciPy-user] odrpack changing the shape of a matrix
James Phillips
zunzun at zunzun.com
Mon May 19 18:12:03 EDT 2008
The example code below demonstrates odrpack changing the shape of a matrix.
I code around this behavior with a dummy 'second list' as shown below.
James Phillips
http://zunzun.com
import numpy, scipy.odr.odrpack
def f(B, x):
if len(x.shape) == 2:
print 'x.shape OK:', x.shape
else:
print 'x.shape ** changed ** --> ', x.shape
return B[0] + x[0]*B[1] + x[0]*x[0]*x[0]*B[2] # constant + ax + bx^3
good_X_data = numpy.array([[1.0, 2.0, 3.0, 4.0, 5.0], [0, 0, 0, 0, 0]]) #
second list is only needed for illustration
bad_X_data = numpy.array([[1.0, 2.0, 3.0, 4.0, 5.0]]) # no second list, the
function f() above shows shape change
ydata = numpy.array([1.0, 2.0, 2.0, 2.0, 3.0])
coefficients = numpy.array([0.89655172413793, 0.33646812957158,
0.00208986415883])
model = scipy.odr.odrpack.Model(f)
goodRealData = scipy.odr.odrpack.RealData(good_X_data, ydata)
badRealData = scipy.odr.odrpack.RealData(bad_X_data, ydata)
# independant data (X) unchanged
myodr = scipy.odr.odrpack.ODR(goodRealData, model, beta0=coefficients,
maxit=0)
myodr.set_job(var_calc=0)
myoutput = myodr.run()
print 'Good Std Error:', myoutput.sd_beta, ' (should be [ 0.81412536
0.45377835 0.0142225 ])'
# independant data (X) changes shape
myodr = scipy.odr.odrpack.ODR(badRealData, model, beta0=coefficients,
maxit=0)
myodr.set_job(var_calc=0)
myoutput = myodr.run()
print 'Bad Std Error:', myoutput.sd_beta, ' (should be [ 0.81412536
0.45377835 0.0142225 ])'
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.scipy.org/pipermail/scipy-user/attachments/20080519/69451371/attachment.html>
More information about the SciPy-User
mailing list