Pregunta

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.

¿Fue útil?

Solución

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.

Otros consejos

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

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top