-
Notifications
You must be signed in to change notification settings - Fork 7
/
hinton.py
executable file
·43 lines (33 loc) · 1.1 KB
/
hinton.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
# coding=utf-8
from __future__ import print_function
import numpy as np
chars = [" ", "▁", "▂", "▃", "▄", "▅", "▆", "▇", "█"]
class BarHack(str):
def __str__(self):
return self.internal
def __len__(self):
return 1
def plot(arr, max_val=None):
if max_val is None:
max_arr = arr
max_val = max(abs(np.max(max_arr)), abs(np.min(max_arr)))
opts = np.get_printoptions()
np.set_printoptions(edgeitems=500)
s = str(np.array2string(arr,
formatter={
'float_kind': lambda x: visual(x, max_val),
'int_kind': lambda x: visual(x, max_val)},
max_line_width=5000
))
np.set_printoptions(**opts)
return s
def visual(val, max_val):
if abs(val) == max_val:
step = len(chars) - 1
else:
step = int(abs(float(val) / max_val) * len(chars))
colourstart = ""
colourend = ""
if val < 0:
colourstart, colourend = '\033[90m', '\033[0m'
return colourstart + chars[step] + colourend