forked from BeenKim/MMD-critic
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHelper.py
34 lines (26 loc) · 910 Bytes
/
Helper.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
# maintained by [email protected]
import os
import numpy as np
def format_numsel(numsel):
ss = ''
for i,j in enumerate(numsel):
ss = ss + " %d:%d " %(i,j)
return ss
def get_train_testindices(n, ntest, seed):
np.random.seed(seed)
testindices = np.random.choice(n,ntest,replace=False)
trainindices = np.setdiff1d( range(n), testindices)
return trainindices, testindices
def exit(str):
print str
exit(1)
def dir_exists(filename):
"""Creates the directory of a file if the directory does not exist.
Raises:
IOError: If the directory could not be created (and the directory does not
exist). This may be due to for instance permissions issues or a race
condition in which the directory is created right before makdirs runs.
"""
dir = os.path.dirname(filename)
if not os.path.exists(dir):
os.makedirs(dir)