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
|
||||
|
||||
|
||||
def write_ftsv(fd, ds):
|
||||
def write_ftsv(fd, ds, decimals=7):
|
||||
"""Writes a dataset in fluents tab separated values (ftsv) form.
|
||||
|
||||
@param fd: An open file descriptor to the output file.
|
||||
|
@ -449,6 +449,7 @@ def write_ftsv(fd, ds):
|
|||
fd = open(fd, 'w')
|
||||
opened = True
|
||||
|
||||
printstr = "%s\t"
|
||||
# Write header information
|
||||
if isinstance(ds, CategoryDataset):
|
||||
type = 'category'
|
||||
|
@ -456,6 +457,7 @@ def write_ftsv(fd, ds):
|
|||
type = 'network'
|
||||
elif isinstance(ds, Dataset):
|
||||
type = 'dataset'
|
||||
printstr = '%%.%df\t' % decimals
|
||||
else:
|
||||
raise Exception("Unknown object")
|
||||
print >> fd, "# type: %s" % type
|
||||
|
@ -477,7 +479,7 @@ def write_ftsv(fd, ds):
|
|||
y, x = m.shape
|
||||
for j in range(y):
|
||||
for i in range(x):
|
||||
print >> fd, "%s\t" % m[j, i],
|
||||
print >> fd, printstr % m[j, i],
|
||||
print >> fd
|
||||
|
||||
if opened:
|
||||
|
|
Reference in New Issue