Skip to content

Instantly share code, notes, and snippets.

@sjmielke
Created August 31, 2017 18:29
Show Gist options
  • Save sjmielke/7f3d82560990bd60eec0e919734e9a2b to your computer and use it in GitHub Desktop.
Save sjmielke/7f3d82560990bd60eec0e919734e9a2b to your computer and use it in GitHub Desktop.
import math
import numpy as np
import sys
"""
Output a 2D gaussian:
░░░░░░░░░░░░░░
░░░░░░░░░░░░░░░░░░░░
░░░░░░░░▒▒▒▒▒▒▒▒░░░░░░░░░░
░░░░░░▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒░░░░░░
░░░░░░▒▒▒▒▓▓▓▓▓▓▓▓▓▓▒▒▒▒░░░░░░
░░░░▒▒▒▒▒▒▓▓▓▓▓▓▓▓▓▓▓▓▓▓▒▒▒▒░░░░
░░░░░░▒▒▓▓▓▓▓▓████████▓▓▓▓▒▒▒▒░░░░
░░░░▒▒▒▒▓▓▓▓██████████▓▓▓▓▒▒▒▒░░░░
░░░░▒▒▒▒▓▓▓▓████████████▓▓▓▓▒▒▒▒░░░░
░░░░▒▒▓▓▓▓██████████████▓▓▓▓▒▒░░░░
░░░░▒▒▒▒▓▓▓▓████████████▓▓▓▓▒▒▒▒░░░░
░░░░▒▒▒▒▓▓▓▓██████████▓▓▓▓▒▒▒▒░░░░
░░░░▒▒▒▒▓▓▓▓████████▓▓▓▓▓▓▒▒░░░░░░
░░░░▒▒▒▒▓▓▓▓▓▓▓▓▓▓▓▓▓▓▒▒▒▒▒▒░░░░
░░░░░░▒▒▒▒▓▓▓▓▓▓▓▓▓▓▒▒▒▒░░░░░░
░░░░░░▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒░░░░░░
░░░░░░░░░░▒▒▒▒▒▒▒▒░░░░░░░░
░░░░░░░░░░░░░░░░░░░░
░░░░░░░░░░░░░░
"""
shades = " ░▒▓█"
var1 = float(sys.argv[1])
c12 = float(sys.argv[2])
c21 = float(sys.argv[3])
var2 = float(sys.argv[4])
def shade(v, maxval=0.2):
s = shades[min(int(len(shades) * v / maxval), len(shades)-1)]
return s + s
def gaussian(x, y):
bfx = np.array([[x,y]])
bfx_T = np.reshape(bfx, (2,1))
cov = np.array([[var1, c12], [c21, var2]])
return np.linalg.det(2 * 3.1415926 * cov) ** (-.5) * math.exp(-.5 * np.dot(np.dot(bfx, cov), bfx_T))
lines = []
for y in np.arange(-5,5,0.2):
vals = []
for x in np.arange(-5,5,0.2):
vals.append(gaussian(x, y))
lines.append(vals)
maxval = max([max(l) for l in lines])
for line in lines:
print("".join([shade(v, maxval) for v in line]))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment