chapter 4 - linear algebra

Vectors and scalars and matrices, oh my.

In [1]:
from scratch.linear_algebra import *
In [17]:
print(dir())
['A', 'B', 'Callable', 'In', 'List', 'Matrix', 'Out', 'Tuple', 'Vector', '_', '_10', '_11', '_12', '_13', '_2', '__', '___', '__builtin__', '__builtins__', '__doc__', '__loader__', '__name__', '__package__', '__spec__', '_dh', '_i', '_i1', '_i10', '_i11', '_i12', '_i13', '_i14', '_i15', '_i16', '_i17', '_i2', '_i3', '_i4', '_i5', '_i6', '_i7', '_i8', '_i9', '_ih', '_ii', '_iii', '_oh', 'add', 'data', 'distance', 'dot', 'exit', 'f', 'friend_matrix', 'friends_of_five', 'friendships', 'get_column', 'get_ipython', 'get_row', 'grades', 'height_weight_age', 'identity_matrix', 'magnitude', 'make_matrix', 'math', 'quit', 'scalar_multiply', 'shape', 'squared_distance', 'subtract', 'sum_of_squares', 'vector_mean', 'vector_sum']
In [22]:
for function in (add, subtract, magnitude, distance, scalar_multiply, dot,
          vector_mean, vector_sum, shape,
          make_matrix, get_row, get_column, identity_matrix):
    help(function)
    print('- '*20)
Help on function add in module scratch.linear_algebra:

add(v:List[float], w:List[float]) -> List[float]
    Adds corresponding elements

- - - - - - - - - - - - - - - - - - - - 
Help on function subtract in module scratch.linear_algebra:

subtract(v:List[float], w:List[float]) -> List[float]
    Subtracts corresponding elements

- - - - - - - - - - - - - - - - - - - - 
Help on function magnitude in module scratch.linear_algebra:

magnitude(v:List[float]) -> float
    Returns the magnitude (or length) of v

- - - - - - - - - - - - - - - - - - - - 
Help on function distance in module scratch.linear_algebra:

distance(v:List[float], w:List[float]) -> float

- - - - - - - - - - - - - - - - - - - - 
Help on function scalar_multiply in module scratch.linear_algebra:

scalar_multiply(c:float, v:List[float]) -> List[float]
    Multiplies every element by c

- - - - - - - - - - - - - - - - - - - - 
Help on function dot in module scratch.linear_algebra:

dot(v:List[float], w:List[float]) -> float
    Computes v_1 * w_1 + ... + v_n * w_n

- - - - - - - - - - - - - - - - - - - - 
Help on function vector_mean in module scratch.linear_algebra:

vector_mean(vectors:List[List[float]]) -> List[float]
    Computes the element-wise average

- - - - - - - - - - - - - - - - - - - - 
Help on function vector_sum in module scratch.linear_algebra:

vector_sum(vectors:List[List[float]]) -> List[float]
    Sums all corresponding elements

- - - - - - - - - - - - - - - - - - - - 
Help on function shape in module scratch.linear_algebra:

shape(A:List[List[float]]) -> Tuple[int, int]
    Returns (# of rows of A, # of columns of A)

- - - - - - - - - - - - - - - - - - - - 
Help on function make_matrix in module scratch.linear_algebra:

make_matrix(num_rows:int, num_cols:int, entry_fn:Callable[[int, int], float]) -> List[List[float]]
    Returns a num_rows x num_cols matrix
    whose (i,j)-th entry is entry_fn(i, j)

- - - - - - - - - - - - - - - - - - - - 
Help on function get_row in module scratch.linear_algebra:

get_row(A:List[List[float]], i:int) -> List[float]
    Returns the i-th row of A (as a Vector)

- - - - - - - - - - - - - - - - - - - - 
Help on function get_column in module scratch.linear_algebra:

get_column(A:List[List[float]], j:int) -> List[float]
    Returns the j-th column of A (as a Vector)

- - - - - - - - - - - - - - - - - - - - 
Help on function identity_matrix in module scratch.linear_algebra:

identity_matrix(n:int) -> List[List[float]]
    Returns the n x n identity matrix

- - - - - - - - - - - - - - - - - - - - 
In [ ]: