forked from viirya/flickr_fetcher
-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils.py
48 lines (31 loc) · 961 Bytes
/
utils.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
44
45
46
47
import sys
import argparse
import re
import os
from numpy import array, zeros, mean, std, sort, add, subtract, divide, dot, sqrt, arange, random
from numpy import linalg as la
#from scipy.cluster.vq import vq, kmeans, whiten
def get_files_in_dir(dirname, random_flag = False):
files = []
fullpath_files = []
filelist = os.listdir(dirname)
for filename in filelist:
full_filename = dirname + '/' + filename
files.append(filename)
fullpath_files.append(full_filename)
if random_flag == True:
random.shuffle(files)
random.shuffle(fullpath_files)
return (array(files), array(fullpath_files))
def load_file(filename):
f = open(filename, 'r')
content = []
for line in f:
content.append(line.rstrip())
f.close()
return array(content)
def write_file(data, filename):
f = open(filename, 'w')
for item in data:
f.write(item + "\n")
f.close()