Skip to end of metadata
Go to start of metadata

math-array utility in snark is a trivial wrapper for a range of numpy array operations. the main purpose of math-array is to easily run array operations on streams of data compatible with the csv-style utilities in comma and snark.

math-array does not attempt to substitute numpy functionality. If you need something customised, just write your own python code as usual.

Currently, it exposes three operations:

  • split
  • transpose
  • (relatively) arbitrary numpy array operation

Examples

Split:

> ( echo some_other_stuff,0,1,2,3,4,5; echo more_other_stuff,6,7,8,9,10,11 ) | csv-to-bin s[32],6f | math-array split --shape 3,2 --header-size 32 | csv-from-bin s[32],2f
some_other_stuff,0,1
some_other_stuff,2,3
some_other_stuff,4,5
more_other_stuff,6,7
more_other_stuff,8,9
more_other_stuff,10,11

Transpose:

> # transpose
> ( echo 0,1,2,3,4,5; echo 6,7,8,9,10,11 ) | csv-to-bin 6f | math-array transpose --to-axes 1,0 --shape 3,2 | csv-from-bin 6f
0,2,4,1,3,5
6,8,10,7,9,11
 
> # the record has not only the array, but also other fields
> ( echo some_other_stuff,0,1,2,3,4,5; echo more_other_stuff,6,7,8,9,10,11 ) | csv-to-bin s[32],6f | math-array transpose --to-axes 1,0 --shape 3,2 --header-size 32 | csv-from-bin s[32],6f
some_other_stuff,0,2,4,1,3,5
more_other_stuff,6,8,10,7,9,11

(Relatively) arbitrary numpy array operation

> # swapaxes
> ( echo some_other_stuff,0,1,2,3,4,5; echo more_other_stuff,6,7,8,9,10,11 ) | csv-to-bin s[32],6f | math-array "np.swapaxes, axis1 = 0, axis2 = 1" --shape 3,2 --header-size 32 | csv-from-bin s[32],6f
some_other_stuff,0,2,4,1,3,5
more_other_stuff,6,8,10,7,9,11

See math-array --help for more details.

 

  • No labels