1

If I don't set the precision, how many decimal places can Numpy be accurate?

I've been dealing with some scientific computing problems for a while now, usually with precision to 15 decimal places, and I don't know if numpy can do this kind of precision.

If not, how can I set the precision?

Lancdorr
  • 335
  • 4
  • 14

2 Answers2

2

Here's a page that might help. https://numpy.org/doc/stable/user/basics.types.html

The bottom line is that numpy uses the default double precision floating point number, which gives you approximately 16 decimal places of precision on most 64 bit systems. Unfortunately it doesn't support more precision than that.

To calculate with more precision, you'll need some Python libraries. Here's something you might find helpful. https://zetcode.com/python/decimal/

ratchek
  • 166
  • 1
  • 8
0

You haven't specified what data type you're using, but numpy's data types documentation could be a good starting point. You can get maximum precision if you use numpy.longdouble, which is platform-specific and usually depends on what your C compiler considers long double.

Without setting the dtype explicitly, you will get 64 bit precision:

>>> import numpy as np
>>> x = np.array([1.0,2.0,3.0])
>>> print(x.dtype)
float64
Ivaylo Toskov
  • 3,911
  • 3
  • 32
  • 48