-
Notifications
You must be signed in to change notification settings - Fork 1
/
createSampleFromFullData.py
43 lines (27 loc) · 835 Bytes
/
createSampleFromFullData.py
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
35
36
37
38
39
40
41
42
43
import numpy as np
import sys
if len(sys.argv) != 3:
print("Error (Not enough input parameters):")
print("1: FileName")
print("2: Num of Points to sample")
exit(1)
datasetFileName = sys.argv[1]
numPointsToSample = int(sys.argv[2])
fin = open(datasetFileName)
allDataLines = []
for line in fin:
if line[0] != "#":
line = line.strip()
allDataLines.append(line)
fin.close()
sampleIds = np.random.choice(allDataLines, numPointsToSample)
## sampleIds will be data points (string)
print("Got ", len(sampleIds), " point ids... Storing to file...")
lastdotIndex = datasetFileName.rfind('.')
foutFileName = datasetFileName[:lastdotIndex] + "_" + str(numPointsToSample) + ".txt"
fout = open(foutFileName, "w")
# print(sampleIds)
for eachId in sampleIds:
lineToWrite = eachId
fout.write(lineToWrite + "\n")
fout.close()