forked from bloominstituteoftechnology/ML-Precourse
-
Notifications
You must be signed in to change notification settings - Fork 0
/
precourse.py
executable file
·68 lines (42 loc) · 1.17 KB
/
precourse.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# Machine Learning/Data Science Precourse Work
# ###
# LAMBDA SCHOOL
# ###
# MIT LICENSE
# ###
# Free example function definition
# This function passes one of the 11 tests contained inside of test.py. Write the rest, defined in README.md, here, and execute python test.py to test. Passing this precourse work will greatly increase your odds of acceptance into the program.
from scipy.misc import derivative
import numpy as np
def f(x):
return x**2
def f_2(x):
return x**3
def f_3(x):
return (x**3) + (5*x)
def d_f(x):
return derivative(f,x)
def d_f_2(x):
return round(derivative (f_2,x,dx=1e-3))
def d_f_3(x):
return round(derivative(f_3,x,dx=1e-3))
def vector_sum(x,y):
x = np.array(x)
y = np.array(y)
return x+y
def vector_less(x,y):
x = np.array(x)
y = np.array(y)
return x-y
def vector_magnitude(x):
return np.linalg.norm(x)
def vec5():
return np.array([1,1,1,1,1],dtype=int)
def vec3():
return np.array([0,0,0],dtype=int)
def vec2_1():
return np.array([1,0],dtype=int)
def vec2_2():
return np.array([0,1],dtype=int)
def matrix_multiply(vec,matrix):
return np.dot(vec, matrix)