vectors(): Some linear algebra exercises with vectors. r = [[1 2 3]] type(r) = r.shape = (1, 3) len(r) = 1 r.T = [[1] [2] [3]] c = [[1] [2] [3]] type(c) = c.shape = (3, 1) len(c) = 3 c.T = [[1 2 3]] 2-norm and max-norms of vectors: 2Norm of [0.08708772 0.63028344] is 0.6362715502230434 MNorm of [0.08708772 0.63028344] is 0.630283440495408 2Norm of [3 4] is 5.0 MNorm of [3 4] is 4.0 2Norm of [1. 1.] is 1.4142135623730951 MNorm of [1. 1.] is 1.0 Magnitude and direction of a vector: v: [2 3] ||v|| = np.linalg.norm(v) = 3.605551275463989 vhat = v / ||v||: [0.5547002 0.83205029] v2 = ||v|| * vhat: [2. 3.] w = 10 * v [20 30] ||w|| = np.linalg.norm(w) = 36.05551275463989 what = w / ||w||: [0.5547002 0.83205029] dot product of w and x: np.dot(w,x) w = np.random.rand ( 2 ) [0.45091203 0.29213392] x = np.random.rand ( 2 ) [0.69490582 0.60677313] np.dot(w,x) = 0.4906004021174127 Cosine of angle between w and x: w dot x / ||w|| / ||x|| ||w|| = 0.5372744951920453 ||x|| = 0.9225333170099113 cos(w,x) = 0.9898049366520131 angle = 0.1429155962005503 radians, 8.188460488887436 degrees norm(x) = sqrt(x dot x ) norm ( x ) = 0.9225333170099113 sqrt(dot(x,x)) = 0.9225333170099113 projection of v onto u u: [3 4] uhat: [0.6 0.8] v: [5 1] beta = np.dot ( v, uhat ) = 3.8 v1: [2.28 3.04] v2: [ 2.72 -2.04] angle (v1,uhat) = 0.0 radians = 0.0 degrees angle (v2,uhat) = 1.5707963267948966 radians = 90.0 degrees