1

I have a torch.FloatTensor that is 2 rows and 200 columns. I want to print the lines to a text file. Is there a toString() method for the torch.FloatTensor? If not, how do you print the line to the file? Thanks.

I can convert the FloatTensor into a Lua table:

    local line = a[1]

    local table = {}
    for i=1,line:size(1) do
        table[i] = line[i]
    end

Is there an easy way to convert the Lua table to a string, so I can write it to file? Thanks!

Brandon Rios
  • 11
  • 1
  • 3
  • There doesn't appear to be any reference to a `toString` method of any kind on what I think is the correct documentation page: https://github.com/torch/torch7/blob/master/doc/tensor.md – MTCoster Dec 08 '15 at 03:10
  • Thanks, I have updated the Q. – Brandon Rios Dec 08 '15 at 03:14
  • There are some great answers to [this question](http://stackoverflow.com/questions/9168058/lua-beginner-table-dump-to-console) which can help you now – MTCoster Dec 08 '15 at 03:22

1 Answers1

2

There is a built-in table conversion called torch.totable. If what you want to do is save and load your tensor, then it's even easier to use Torch native serialization like torch.save('file.txt', tensor, 'ascii').

deltheil
  • 15,496
  • 2
  • 44
  • 64