-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdump.py
More file actions
35 lines (26 loc) · 792 Bytes
/
dump.py
File metadata and controls
35 lines (26 loc) · 792 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import sys
import h5py
import numpy as np
filename = sys.argv[1]
normalize = False
if '-normalize' in sys.argv:
normalize = True
f = h5py.File(filename, 'r')
# ['distances', 'neighbors', 'test', 'train']
# file format:
train = f.get('train')[()]
test = f.get('test')[()]
gtruth = f.get('neighbors')[()]
print(train.shape,train.dtype)
print(test.shape,test.dtype)
print(gtruth.shape,gtruth.dtype)
print(train.shape,train.dtype)
print(test.shape,test.dtype)
print(gtruth.shape,gtruth.dtype)
if normalize:
train /= ( np.linalg.norm(train, axis = 1, keepdims = True) + 1e-30 )
test /= ( np.linalg.norm(test, axis = 1,keepdims = True) + 1e-30)
fname = filename.replace('.hdf5','')
np.save(fname+".train", train)
np.save(fname+".test", test)
np.save(fname+".gtruth", gtruth)