Skip to content

Commit 6be0238

Browse files
committed
Added helper functions in Utils.py
1 parent 258cabc commit 6be0238

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

nicenet/Utils.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import random
2+
from math import floor
3+
import numpy as np
4+
5+
6+
def shuffleArray(array: list):
7+
arrayCopy = array.copy()
8+
random.shuffle(arrayCopy)
9+
10+
return arrayCopy
11+
12+
13+
def splitArr(array: list, ratio: float):
14+
n = len(array)
15+
16+
m = floor(n * ratio)
17+
18+
firstPart: list = array[0: m]
19+
secondPart: list = array[m: n]
20+
21+
return [firstPart, secondPart]
22+
23+
24+
def one_hot_encode(num, size):
25+
vector = np.array([0]*size)
26+
vector[num-1] = 1
27+
28+
return vector.reshape(size, 1)
29+
30+
31+
def get_time_required(start, end, epochs):
32+
seconds = (end - start) * epochs
33+
34+
minutes = seconds // 60
35+
seconds = seconds % 60
36+
37+
hours = minutes // 60
38+
minutes = minutes % 60
39+
return f"Estimated Training Time: {hours}hrs::{minutes}min::{round(seconds, 4)}sec"

0 commit comments

Comments
 (0)