[Numpy-discussion] printing structured arrays
Fri Mar 5 16:35:44 CST 2010
On Fri, Mar 5, 2010 at 8:00 AM, Bruce Schultz <email@example.com>wrote:
> I've just started playing with numpy and have noticed that when printing a
> structured array that the output is not nicely formatted. Is there a way to
> make the formatting look the same as it does for an unstructured array?
> Here an example of what I mean:
> data = [ (1, 2), (3, 4.1) ]
> dtype = [('x', float), ('y', float)]
> print '### ndarray'
> a = numpy.array(data)
> print a
> print '### structured array'
> a = numpy.array(data, dtype=dtype)
> print a
> Output is:
> ### ndarray
> [[ 1. 2. ]
> [ 3. 4.1]]
> ### structured array
> [(1.0, 2.0) (3.0, 4.0999999999999996)]
> NumPy-Discussion mailing list
I still couldn't figure out how floating point numbers look nicely on screen
in cases like yours (i.e., trying numpy.array2string()) but you can make
sure by using numpy.savetxt("file", array, fmt="%.1f") you will always have
specified precision in the written file.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the NumPy-Discussion