0

I found that it is possible to disable scientific notation for numpy objects with np.set_printoptions(suppress=True). It does not however work for 'normal' variables, i.e. not numpy python floats:

a = 0.0000000000000000001
b = np.array([a])
print(a)
print(b)

The output is

1e-19
[0.]

and we see that the variable a is still printed with scientific notation. Is there a way to completely disable scientific notation for all variables in python?

In R you can do it for virtually every scenario with options(scipen=999) :

> 0.000000001
[1] 1e-09
> options(scipen=999)
> 0.000000001
[1] 0.000000001
> 0.0000000000000000000000000000000001
[1] 0.0000000000000000000000000000000001
Sinusx
  • 111
  • 3
  • Does this answer your question? [How to suppress scientific notation when printing float values?](/q/658763/4518341) It's not possible to do it the same way as NumPy, but if you specifically want this for interactive sessions, you could use IPython; see [set ipython's default scientific notation threshold](/q/16866761/4518341). (OP there wants a different format, but the answer points you in the right direction.) – wjandrea Sep 17 '22 at 22:35
  • @wjandrea Thanks, I see now with the comment by BLUC in your link that it is in fact not possible. – Sinusx Sep 18 '22 at 10:22

1 Answers1

2

Suppress for numpy.array:

np.set_printoptions(suppress=True, precision=6)

Print format for floats:

print(f'{a:f}')

Result:

np.set_printoptions(suppress=True, precision=6)

a = 0.0000000000000000001
b = np.array([a])
print(f'{a:f}')
print(b)

# 0.000000
# [0.]
zalevskiaa
  • 174
  • 5