Skip to content

Instantly share code, notes, and snippets.

  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save duhaime/0f7c3bcb58b5b8b70ccd18f7e90429d7 to your computer and use it in GitHub Desktop.
import numpy as np
import sys
import struct
dim = 50
a = np.load('stacked-vecs-{}.npy'.format(dim))
with open('stacked.fvecs', 'wb') as out:
for i in a:
line = [float(j) for j in i]
out.write(struct.pack('=I', dim))
out.write(struct.pack('={}{}'.format(dim, 'f'), *line))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment