This file contains hidden or 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 centrifugal(series, k=1): | |
mu = np.mean(series) | |
return mu + k * np.subtract(series, mu) | |
if __name__ == '__main__': | |
arr = [2, 4, 6] |
This file contains hidden or 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
from math import factorial, sqrt, pi, e | |
import time | |
def fact(x): | |
return sqrt(2*pi*x) * (x / e) ** x | |
if __name__ == '__main__': | |
x = 125 |
This file contains hidden or 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 shifter(phrase, shift=1): | |
a = ord('a') | |
N = ord('z') - a + 1 | |
output = '' | |
for char in phrase.lower(): | |
if char.isalpha(): | |
ordinal = (ord(char) - a + shift) % N + a | |
char = chr(ordinal) |
This file contains hidden or 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
from functools import partial | |
import operator as op | |
import math | |
def to_polar(point, origin=(0, 0)): | |
assert len(point) == len(origin) == 2 | |
dx = point[0] - origin[0] | |
dy = point[1] - origin[1] | |
d = math.sqrt(dx**2 + dy**2) | |
r = math.atan2(dy, dx) |
This file contains hidden or 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
from functools import partial | |
import operator as op | |
import numpy as np | |
def length(array): | |
assert np.ndim(array) == 1 | |
return np.shape(array)[0] | |
def all_positive(array): |
This file contains hidden or 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 convert(value): | |
value = str(value).lower() | |
if value == 'rock': | |
return 0 | |
elif value == 'paper': | |
return 1 | |
elif value == 'scissors': | |
return 2 | |
return -1 |
This file contains hidden or 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 perfect_cube(n): | |
return [ | |
tuple(map(int, row[2:].rjust(n, '0'))) | |
for row in map(bin, range(2**n)) | |
] | |
if __name__ == "__main__": | |
from pprint import pprint |
This file contains hidden or 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
class Node: | |
def __init__(self, identifier, priority): | |
self.identifier = identifier | |
self.priority = priority | |
def set_priority(self, value): | |
self.priority = value | |
def __gt__(self, other): | |
return self.priority > other.priority |
This file contains hidden or 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 matrix_multiplication(A, B): | |
m = len(A) | |
n = len(A[0]) | |
n2 = len(B) | |
k = len(B[0]) | |
assert n == n2 | |
assert all(len(row)==n for row in A) | |
assert all(len(row)==k for row in B) |
This file contains hidden or 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 datetime as dt | |
import mimetypes | |
import requests | |
import json | |
import os | |
BASE_URL = "https://api.github.com/users/{username}/gists" | |
def clean(clause, fill='-', encoding='ascii'): | |
return clause.strip().replace(' ', fill).encode(encoding, 'ignore').decode(encoding) |
NewerOlder