A simple CSV library for reading / writing Torch tensor objects.
From a terminal:
luarocks install thcsv
then:
thcsv = require 'thcsv'
output = thcsv.read(csvFile, [skipFirst = false])
Reads the content of file csvFile
and store it into output
. The output
tensor will have a size of nRows x nCols
. For CSV files with a header containing a list of field names, you must call the function with skipFirst = true
.
thcsv.write(csvFile, input, [header = {}])
Write the content of input
into file csvFile
, where input
is a nRows x nCols
tensor. Additionally, provide a table of field names header = {id1, id2, ...}
to add a header to the CSV file.
thcsv = require 'thcsv'
thcsv.write('eye.csv', torch.eye(5))
output = thcsv.read('eye.csv')
output
1 0 0 0 0
0 1 0 0 0
0 0 1 0 0
0 0 0 1 0
0 0 0 0 1
[torch.DoubleTensor of size 5x5]