In [5]:
# Getting set up to use the NumPy Library
import numpy as np
In [8]:
# Arrays have shape (dimensions) and data types
rows = 1
cols = 3
np.zeros(shape=(rows, cols), dtype=float)
Out[8]:
In [9]:
# Arrays have shape (dimensions) and data types
rows = 3
cols = 3
np.zeros(shape=(rows, cols), dtype=float)
Out[9]:
In [11]:
# Three dimensional array
rows = 3
cols = 3
depth = 3
np.zeros(shape=(rows, cols, depth), dtype=float)
Out[11]:
In [14]:
my_ones = np.ones(shape=(rows, cols), dtype=int)
my_ones
Out[14]:
In [13]:
print(my_ones)
In [31]:
a = np.arange(16)
In [32]:
a
Out[32]:
In [33]:
a[0:4]
Out[33]:
In [34]:
a[4:6]
Out[34]:
In [35]:
a[0:]
Out[35]:
In [36]:
a[:]
Out[36]:
In [40]:
a[:-1]
Out[40]:
In [39]:
a[::-1]
Out[39]:
In [38]:
a + 20
Out[38]:
In [41]:
a
Out[41]:
In [42]:
a.reshape(4, 4)
Out[42]:
In [46]:
a.cumsum()
Out[46]:
In [51]:
M = np.matrix('1.0 2.0 3.0 4.0; 5.0 6.0 10.0 11.0; 12.0 20.0 50.0 9.0')
In [52]:
M
Out[52]:
In [53]:
# Transpose
M.T
Out[53]:
In [62]:
X = np.matrix('100 0 0 0; 0 100 0 0; 0 0 100 0')
X
Out[62]:
In [63]:
M + X
Out[63]:
In [64]:
# Inverse
X.I
Out[64]:
In [1]:
print("Hello Linear Algebra")
In [2]:
print("Numbers, numbers, and more numbers")
In [18]:
import matplotlib.pyplot as plt
x = np.arange(-20, 20, 0.25)
y = x.reshape(-1, 1)
r = np.sqrt(x**2 + y**2)
z = np.cos(r) / (r + 5)
plt.show(z)
In [16]:
plt.clf()
plt.imshow(z, origin = 'lower', vmin = -10, vmax = 65)
plt.colorbar()
Out[16]:
In [ ]: