Put this above your code:
def tensor_to_string(self):
return str(self.tolist())
setattr(torch.Tensor, 'tostring', tensor_to_string)
To use, just write
(tensor name).tostring()
Example:
test = torch.randn(4)
print(type(test.tostring()))
print(test.tostring())
Output:
<class 'str'>
[-0.6502066850662231, -1.1002898216247559, -0.7664051651954651, -0.4823172092437744]