4

This is a very simple question but I don't know the right words to Google. I have a numpy array:

A = np.array([ 8.1588e-01, -3.9675e-04])

And I would like to print it as normal decimal numbers. That is 0.81588, -0.00039675.

How can you do that?

Simd
  • 19,447
  • 42
  • 136
  • 271

1 Answers1

4

Numpy let's you customize the output globally using set_printoptions.

To get rid of scientific notation, you can use:

 np.set_printoptions(suppress=True) # don't use scientific notation

From the documentation:

suppress : bool, optional

If True, always print floating point numbers using fixed point notation, in which case numbers equal to zero in the current precision will print as zero. If False, then scientific notation is used when absolute value of the smallest number is < 1e-4 or the ratio of the maximum absolute value to the minimum is > 1e3. The default is False.

Coder
  • 1,175
  • 1
  • 12
  • 32
Derlin
  • 9,572
  • 2
  • 32
  • 53
  • While `set_printoptions` would be the function to use, neither of your example calls produce the desired output given in the question. – user2357112 Jun 09 '18 at 07:41
  • @user2357112 good catch ! I didn't pay attention. Updated my answer. – Derlin Jun 09 '18 at 07:44
  • @Anush: Watch out for truncation; the truncation behavior of `suppress` doesn't work like what you have in your question, and whatever truncation behavior you're hoping for, it's unlikely you'll find a convenient way to get it. – user2357112 Jun 09 '18 at 08:19