Added a "decimals" parameter to write_ftsv, so that datasets can be written
without full precision. Defaults to 7 digits after decimal point.
This commit is contained in:
parent
a6af506ae0
commit
26ab6c3fe7
|
@ -437,7 +437,7 @@ class Selection(dict):
|
||||||
self[axis] = labels
|
self[axis] = labels
|
||||||
|
|
||||||
|
|
||||||
def write_ftsv(fd, ds):
|
def write_ftsv(fd, ds, decimals=7):
|
||||||
"""Writes a dataset in fluents tab separated values (ftsv) form.
|
"""Writes a dataset in fluents tab separated values (ftsv) form.
|
||||||
|
|
||||||
@param fd: An open file descriptor to the output file.
|
@param fd: An open file descriptor to the output file.
|
||||||
|
@ -449,6 +449,7 @@ def write_ftsv(fd, ds):
|
||||||
fd = open(fd, 'w')
|
fd = open(fd, 'w')
|
||||||
opened = True
|
opened = True
|
||||||
|
|
||||||
|
printstr = "%s\t"
|
||||||
# Write header information
|
# Write header information
|
||||||
if isinstance(ds, CategoryDataset):
|
if isinstance(ds, CategoryDataset):
|
||||||
type = 'category'
|
type = 'category'
|
||||||
|
@ -456,6 +457,7 @@ def write_ftsv(fd, ds):
|
||||||
type = 'network'
|
type = 'network'
|
||||||
elif isinstance(ds, Dataset):
|
elif isinstance(ds, Dataset):
|
||||||
type = 'dataset'
|
type = 'dataset'
|
||||||
|
printstr = '%%.%df\t' % decimals
|
||||||
else:
|
else:
|
||||||
raise Exception("Unknown object")
|
raise Exception("Unknown object")
|
||||||
print >> fd, "# type: %s" % type
|
print >> fd, "# type: %s" % type
|
||||||
|
@ -477,7 +479,7 @@ def write_ftsv(fd, ds):
|
||||||
y, x = m.shape
|
y, x = m.shape
|
||||||
for j in range(y):
|
for j in range(y):
|
||||||
for i in range(x):
|
for i in range(x):
|
||||||
print >> fd, "%s\t" % m[j, i],
|
print >> fd, printstr % m[j, i],
|
||||||
print >> fd
|
print >> fd
|
||||||
|
|
||||||
if opened:
|
if opened:
|
||||||
|
|
Reference in New Issue