In [1]:
import numpy as np
import matplotlib.pyplot as plt
In [2]:
ar1 = [1,2,3,4] # from lists
ar1 = np.array(ar1)
ar1
Out[2]:
In [4]:
# from matlab style syntax
ar2 = np.mat('1,2,3;4,5,6')
ar2
Out[4]:
In [5]:
squares = np.array([4,9,16,25,36,49])
np.sqrt(squares)
Out[5]:
In [6]:
np.min(squares)
Out[6]:
solve $f(x) = 3x^{2} + 2x -6$ for the range -2:0.1:2
In [45]:
x = np.arange(start=-2.0, stop=2.0, step=0.1)
x
Out[45]:
In [51]:
a=np.array([1,2,3])
a*a # element wise
Out[51]:
In [52]:
np.dot(a,a) # matrix multiplication. It automatically changed second a to a col vector
Out[52]:
In [54]:
np.cross(a,a)
Out[54]:
In [55]:
# thus, y
y = 3*x*x + 2*x -6
y
Out[55]:
In [58]:
plt.plot(x,y)
plt.title('$f(x) = 3x^{2} + 2x -6$')
plt.xlabel('x')
plt.ylabel('y');
In [7]:
np.arange(start=0, stop=21, step=2)
Out[7]:
In [9]:
v1 = np.linspace(start=1,stop=10, num=7)
v1
Out[9]:
In [10]:
v1 > 4
Out[10]:
In [41]:
v1[v1>4]
Out[41]:
In [40]:
v1[(v1>4) & (v1<9)]
Out[40]: