Solved

numpy/scipy polyfit precision

Posted on 2012-03-18
2
667 Views
Last Modified: 2012-03-18
I am trying to use numpy to perform a polyfit on a set of very large integers (~256bits).  The points for the line are generated by randomly assigning coefficients and then picking X values at random.  I then try to use numpy to recreate the polynomial from just those points, but the answer is not exact.  It is usually off by less than 10, but it shouldn't be.  Is there a way to turn up the precision for numpy?  matlab is able to crunch these numbers and come up with the exact polynomial, so I would expect numpy to be able to do the same.
0
Comment
Question by:mattjp88
2 Comments
 
LVL 3

Accepted Solution

by:
defc0n1 earned 500 total points
ID: 37734769
As far as I know numpy does not support higher than double precision (float64).

Maybe mpmath can be useful for you.
They support real and complex numbers with arbitrary precision.

EDIT:

Forgot to mention there is also mlabwrap which gives you all of Matlab`s functionality in python.
0
 
LVL 6

Author Closing Comment

by:mattjp88
ID: 37735658
Thanks for pointing out mpmath, it looks promising.

This was a small piece of a larger project, and fitting a polynomial ended up being only one method to get the answer we needed.  So we switched algorithms, so I wont be able to verify any other answers to this question.

the mention of mpmath and mlabwrap is enough to award points I think.
0

Featured Post

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Dictionaries contain key:value pairs. Which means a collection of tuples with an attribute name and an assigned value to it. The semicolon present in between each key and values and attribute with values are delimited with a comma.  In python we can…
Article by: Swadhin
Introduction of Lists in Python: There are six built-in types of sequences. Lists and tuples are the most common one. In this article we will see how to use Lists in python and how we can utilize it while doing our own program. In general we can al…
Learn the basics of strings in Python: declaration, operations, indices, and slicing. Strings are declared with quotations; for example: s = "string": Strings are immutable.: Strings may be concatenated or multiplied using the addition and multiplic…
Learn the basics of if, else, and elif statements in Python 2.7. Use "if" statements to test a specified condition.: The structure of an if statement is as follows: (CODE) Use "else" statements to allow the execution of an alternative, if the …

773 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question