Skip to content

Instantly share code, notes, and snippets.

View BenTenmann's full-sized avatar

outofthebox BenTenmann

View GitHub Profile
def f(z):
y = 1/(1+exp(-z))
return y
@BenTenmann
BenTenmann / perc_1.py
Created January 15, 2021 20:46
tds_2
# importing the necessary modules
import numpy as np
from itertools import product
from math import exp
from scipy.stats import uniform
inputs = list(product([-1,1], repeat=10)) # a list of all the input vectors
# more precisely this function returns
# the 1024 possible permutations of the
# 10-dimensional binary sequence in the
@BenTenmann
BenTenmann / dist_mat.py
Last active January 10, 2021 09:13
tds_1
import numpy as np
from scipy.stats import uniform
n_cities = 500
coords = uniform.rvs(size=n_cities) + uniform.rvs(size=n_cities)*1j
def dist(a, b): # calculates distance between two points
d = abs(a - b)
return d
@BenTenmann
BenTenmann / outer.py
Created January 10, 2021 09:06
tds_1
import numpy as np
u = [1,3,5,2,7,8,10]
v = [5,2,7,2,3,10,4]
M = np.outer(u, v)
print(M)
@BenTenmann
BenTenmann / map.py
Created January 10, 2021 09:04
ads_1
u = [1,3,5,2,7,8,10]
v = [5,2,7,2,3,10,4]
M = list(map(lambda i, j: i * j,
[i for i in u for j in v],
v*len(u)))
print(M)
@BenTenmann
BenTenmann / ls_comp.py
Last active January 10, 2021 09:05
tds_1
u = [1,3,5,2,7,8,10]
v = [5,2,7,2,3,10,4]
M = [i * j for i in u for j in v]
print(M)
u = [1,3,5,2,7,8,10]
v = [5,2,7,2,3,10,4]
M = []
for i in u:
row = []
for j in v:
row.append(i * j)