def dump(result, fname, no_prefix=False):
"""Save result to file."""
result = result.eval() if hasattr(result, "eval") else result
result = np.asarray(result)
if result.shape == (): # savetxt has problems with scalars
result = np.expand_dims(result, 0)
if no_prefix:
location = os.getcwd()+"/"+fname
else:
location = os.getcwd()+"/data/"+fname
# special handling for integer datatypes
if (
result.dtype == np.uint8 or result.dtype == np.int8 or
result.dtype == np.uint16 or result.dtype == np.int16 or
result.dtype == np.uint32 or result.dtype == np.int32 or
result.dtype == np.uint64 or result.dtype == np.int64
):
np.savetxt(location, result, fmt="%d", delimiter=',')
else:
np.savetxt(location, result, delimiter=',')
print(location)
评论列表
文章目录