Open TheNewSound opened 3 years ago
Any interest in submitting a PR? Would love to have this functionality!
Since I am on a tight schedule, I currently solved this problem with the following (not using .npy file format):
Export in javascript:
const array = new Float32Array([1,2,3,4]);
const buffer = Buffer.from(array.buffer);
fs.writeFileSync("output/matrix.bin", buffer);
Import in python:
import math
import numpy as np
filename = '../node/output/matrix.bin'
with open(filename, 'rb') as f:
simmatrix_flat = np.fromfile(f, dtype=np.float32)
print(f'Read file "{filename}" containing a matrix of size: {simmatrix_flat.size}')
#reshape matrix
simmatrix = np.reshape(simmatrix_flat, [math.isqrt(simmatrix_flat.size), math.isqrt(simmatrix_flat.size)])
I might implement this feature in the future, however, don't count on it.
Title says it all.
Would it be possible to include a
save()
function for TypedArrays and regular arrays? For both NodeJS filesystem as in-browser download? This way I can export my javascript arrays to python/numpy.