Hi everyone,
I've looked in the mailing list archives and with the googles, but haven't yet
found any hints with this question...
I have a float field in a NumPy record that looks like it's being substituted
as a string in the Python {:f}.format() mini-language, thus throwing an error:
In
You can treat a record in a record array like a tuple or a dictionary when
it comes to formatting. So, either refer to the index element you want
formatted as a float, or refer to it by name (in the formatting language).
By just doing {:f}, you are just grabbing the first one, which is XXYYZZ
and
On Thu, Jun 6, 2013 at 8:48 PM, Maccarthy, Jonathan K jkm...@lanl.gov wrote:
Hi everyone,
I've looked in the mailing list archives and with the googles, but haven't
yet found any hints with this question...
I have a float field in a NumPy record that looks like it's being substituted
as a
Ah, so np.int64 and np.str inherit the native Python __format__(), but
np.float32/64 doesn't get __builtin__.float.__format__(). That's not
intuitive, but I see now why this works:
In [8]: '{:6.6s} {:8d} {:11.6f}'.format(tmp.sta, tmp.ondate, float(tmp.lat))
Out[8]: 'XYZZ2001123
On Thu, Jun 6, 2013 at 9:18 PM, Maccarthy, Jonathan K jkm...@lanl.gov wrote:
Ah, so np.int64 and np.str inherit the native Python __format__(), but
np.float32/64 doesn't get __builtin__.float.__format__(). That's not
intuitive, but I see now why this works:
In [8]: '{:6.6s} {:8d}
I'm really showing my ignorance now, I think; so, the old-style fmt %
(tuple) must use a different mechanism, and perhaps that's why np.savetxt
never choked on a float32 for me before (yes, I am on a 64-bit system).
In [8]: type(tmp.lat)
Out[8]: numpy.float32
In [9]: '%6s %8i %11.6f' %
On Thu, Jun 6, 2013 at 9:50 PM, Maccarthy, Jonathan K jkm...@lanl.gov wrote:
I'm really showing my ignorance now, I think; so, the old-style fmt %
(tuple) must use a different mechanism, and perhaps that's why np.savetxt
never choked on a float32 for me before (yes, I am on a 64-bit system).