-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathhelpers.py
43 lines (28 loc) · 801 Bytes
/
helpers.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
from typing import Dict
import random
from math import floor
import numpy as np
def custom_argmax(data: Dict[str, float]):
max_key = None
max_value = None
for key in data:
if max_key == None:
max_key = key
if max_value == None or max_value < data[key]:
max_value = data[key]
max_key = key
return max_key
def shuffle_array(array: list):
array_copy = array.copy()
random.shuffle(array_copy)
return array_copy
def split_arr(array: list, ratio: float):
n = len(array)
m = floor(n * ratio)
first_part: list = array[0: m]
second_part: list = array[m: n]
return [first_part, second_part]
def one_hot_encode(num, size) :
vector = np.array([0]*size)
vector[num-1] = 1
return vector.T