1

I currently have a numpy array of float64s:

[ -2.75090260e-08   3.11586226e-08   1.86128266e-08  -1.01560789e-07 ]

which I would like to print as for an excel spreadsheet import:

[ -.0000000275090260   .0000000311586226   .0000000186128266   -.000000101560789 ]

I've tried messing about with precision settings, but each number has its own mantissa and exponent.

Note that these output numbers can be considered a string if that makes the process easier, as they are going into a text file for excel.

  • possible duplicate of [Pretty-printing of numpy.array](http://stackoverflow.com/questions/2891790/pretty-printing-of-numpy-array) – Ashwini Chaudhary Mar 28 '14 at 18:31
  • 1
    If this is for Excel, either format will be treated the same. To get it to look different in Excel, you have to change the number format there. – JaminSore Mar 28 '14 at 18:43

2 Answers2

2

You want to print the numbers in decimal format with 16 digits precision? How about this?

a = [-2.75090260e-08, 3.11586226e-08, 1.86128266e-08, -1.01560789e-07]
print map(lambda x: "{0:.16f}".format(x), a)

This prints

['-0.0000000275090260', '0.0000000311586226', '0.0000000186128266', '-0.0000001015607890']

Update:

You don't even need the lambda. Using

map("{0:.16f}".format, a)

works just as well. Thanks @JaminSore for pointing that out.

Carsten
  • 17,991
  • 4
  • 48
  • 53
-1

Note that you also have the option of: numpy.round(_array, _decimalPrecision)

songololo
  • 4,724
  • 5
  • 35
  • 49