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 | |
import matplotlib.pyplot as plt | |
def midpoint(p1, p2): | |
x1, y1 = p1 | |
x2, y2 = p2 | |
return (x1+x2)/2, (y1+y2)/2 | |
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 approximate_pi(n): | |
points = np.random.uniform(-1, 1, (n, 2)) | |
inside = np.sum(points[:,0]**2+points[:,1]**2 <= 1) | |
k = inside/n | |
return 4*k | |
n = 1000000 |
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 typing import List, Any | |
class Node: | |
def __init__(self, key, value, nxt=None): | |
self.key: str = key | |
self.value: Any = value | |
self.nxt: Node = nxt | |
class LinkedList: |
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 pandas as pd | |
import numpy as np | |
import matplotlib.pyplot as plt | |
def update_annot(ind): | |
pos = sc.get_offsets()[ind["ind"][0]] | |
annot.xy = pos | |
attributes_to_show = [0, 1, 2, 7] | |
text = df.iloc[ind["ind"][0], attributes_to_show].to_string() |
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
# 1st approach: | |
def kth_largest(arr, k): | |
for i in range(k-1): | |
arr.remove(max(arr)) | |
return max(arr) | |
# 2nd approach: | |
def kth_largest(arr, k): | |
n = len(arr) |
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 pulp | |
import pandas as pd | |
import numpy as np | |
"""Example drivers.csv file: | |
driver_id,lat,lon | |
dr_1,10,20 | |
dr_2,30,50 | |
dr_3,50,40 | |
dr_4,80,20 |
OlderNewer