Let's try some Math.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Brackets always start at 0. Enter the beginning of each tax bracket in the array | |
# all the way to the last one. | |
brckts = [0,11000,44725,95375,182100,231250,578125] | |
rates = [.1, .12, .22, .24, .32, .35, .37] | |
def calc_tax(brckts, rates, taxable_income=100000): | |
tax = 0 | |
for i in range(len(rates)-1): | |
if taxable_income > brckts[i+1]: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
from PIL import Image, ImageDraw | |
def rotation(n, theta=np.pi/3): | |
""" | |
Returns a general rotation matrix of any dimensionality. | |
This is achieved by a sequence of successive 2d rotations. | |
http://www.continuummechanics.org/rotationmatrix.html | |
args: | |
n : The dimensionality of the space in which we are going to rotate things. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
""" | |
https://math.stackexchange.com/questions/4660754/can-an-arbitrary-3-d-shape-be-fitted-inside-a-cube-so-it-touches-all-the-sides/4660761?noredirect=1#comment9845446_4660761 | |
""" | |
def make_span_same(sq, r, ix1, ix2): | |
while abs(span(sq, ix1) - span(sq, ix2)) > 1e-2: | |
sq = np.dot(sq, r) | |
return sq |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def fft_3(x): | |
""" | |
Perform a fast Fourier transform | |
on the given array of complex numbers. | |
The arrays size should be a power of 3. | |
""" | |
n = len(x) | |
if n == 1: | |
return x | |
# The complex roots of unity. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
def fft_2(a): | |
""" | |
Perform a fast Fourier transform | |
on the array, a. The size of the array | |
has to be a power of 2. Otherwise, it will | |
yield incorrect results. | |
""" | |
n = len(a) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def polynom_mult(a, b): | |
""" | |
Multiplies two polynomials given in coefficient form. | |
The input arrays a and b represent the coefficients. | |
""" | |
# The output polynomial initialized to | |
# an array of zeros. | |
c = [0]*(len(a)+len(b)-1) | |
# This double loop is the distributive law |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
import networkx as nx | |
from PIL import Image, ImageDraw, ImageFont | |
#Coordinates of all the cities for plotting on a picture. | |
coord = { | |
'staging-1': (362, 47), | |
'staging-2': (908, 140), | |
'staging-3': (1130, 260), |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ukr_grph_ts = { | |
'staging-1': {'chernihiv': 5}, | |
'chernihiv': {'brovary': 4}, | |
'brovary': {'kyiv': 1}, | |
'boryspil': {'kyiv': 1.3, 'pereiaslav': 2.3}, | |
'pereiaslav': {'boryspil': 3.3, 'kremenchuk': 2.5}, | |
'kremenchuk': {'cherkasy': 2.3, 'pereiaslav': 3.1, 'poltava': 2.6, 'dnipro': 2.4, 'kropyvnytskyi': 2.0}, | |
'cherkasy': {'kyiv': 3.2, 'kremenchuk': 2.2}, | |
'bila_tserkva': {'kyiv': 3.1, 'uman': 2.5}, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
from scipy.stats import norm, lognorm, expon, lomax, weibull_min | |
import matplotlib.pyplot as plt | |
def prcntl(a, q, interpolate=1): | |
a = sorted(a) | |
n = len(a) | |
lt = int(np.floor(q*(n-1))) | |
frac = 0 |
NewerOlder