Data reading utility (including TypedArray), Browserify aware
npm install arrayloaderTypedArray reading utility, Browserify aware.
Uses fs.readFile in node, and XHR when browserified.
npm install arrayloader
``javascript`
var loader = require('arrayloader');
loader.load('/path/to/array.f32', function (err, arr) {
// arr is a Float32Array
console.log(arr);
});
write compatible arrays from numpy like this,
`python`given array 'a'
with open('/path/to/array.f32', 'wb') as f:
f.write(a.astype(np.float32).tostring())
choose an extension for your file like this,
extension | TypedArray | numpy dtype | mime type
---------|------------|--------------|-----
i8 | Int8Array | int8 | application/x-int8Uint8Array
u8 | | uint8 | application/x-uint8Int16Array
i16 | | int16 | application/x-int16Uint16Array
u16 | | uint16 | application/x-uint16Int32Array
i32 | | int32 | application/x-int32Uint32Array
u32 | | uint32 | application/x-uint32Float32Array
f32 | | float32 | application/x-float32Float64Array
f64 | | float64 | application/x-float64
or (for non-binary types) like this,
extension | type | mime type
---------|-------|-----
json | json | application/json
key | json | application/json
txt | str | text/plain
csv | str | text/plain
tsv | str | text/plain
Extensions mapped to json will be parsed (with JSON.parse) before
returning.
.Type inference can be overridden by supplying a second argument. If this argument
is supplied but not recognized, the function returns immediately with an error. If supplied, this argument should be a string containing any of the values listed in the "numpy dtype" column from the first table or the "type" column from the second.
Extras
Files in this format can be read into python/numpy like this,
`python
with open(doc_dir + 'array.f32', 'rb') as f:
a = np.fromstring(f.read(), dtype="float32")
``