Revist Revist - 2 months ago 11
Python Question

Converting an array of floats to an array of strings in scientific notation

I want to convert the array created by numpy.linspace(1,10,1) to an array od strings in a scientific notation. How to do this?


You can iterate over the elements of the array, and convert them to strings one by one:

array = numpy.linspace(1, 10, 1)
["%e" % x for x in array]

Here %e renders the number in scientific notation. You can also use %f for a notation with decimal point, or %g for auto-choice between different representations.