Fork me on GitHub
Arraymancer Technical reference Tutorial Spellbook (How-To's) Under the hood

Module io_csv

Search:
Group by:

Procs

proc read_csv[T: SomeNumber | bool | string](csvPath: string; skip_header = false;
                                       separator = ','; quote = '\"'): Tensor[T] {.
noInit
.}

Load a csv into a Tensor. All values must be of the same type.

If there is a header row, it can be skipped.

Input:
  • csvPath: a path to the csvfile
  • skip_header: should read_csv skip the first row
  • separator: a char, default ','
  • quote: a char, default '"' (single and double quotes must be escaped). Separators inside quoted strings are ignored, for example: "foo", "bar, baz" corresponds to 2 columns not 3.
  Source Edit
proc to_csv[T](tensor: Tensor[T]; csvPath: string; separator = ',')

Stores a tensor in a csv file. Can handle tensors of arbitrary dimension by using a schema (= csv columns) of

dimension_1, dimension_2, ..., dimension_(tensor.rank), value

where the 'dimension_i' columns contain indices, and the actual tensor values are stored in the 'value' column.

For example the tensor @[@[1, 2, 3], @[4, 5, 6]].toTensor() is stored as:

dimension_1,dimension_2,value 0,0,1 0,1,2 0,2,3 1,0,4 1,1,5 1,2,6

Input:
  • tensor: the tensor to store
  • csvPath: output path of the csvfile
  • separator: a char, default ','
  Source Edit