. Define the following vectors and matrices:
vec1 = np.array([ -1., 4., -9.])
mat1 = np.array([[ 1., 3., 5.], [7., -9., 2.], [4., 6., 8. ]]
Perform the following operations on the vector and matrices given above:
a. You can multiply vectors by constants.
Compute vec2 = (np.pi/4) * vec1
b. The cosine function can be applied to a vector to yield a vector of cosines.
Compute 1 vec2 = np.cos( vec2 )
import numpy as np
vec1 = np.array([ -1., 4., -9.])
mat1 = np.array([[ 1., 3., 5.], [7., -9., 2.], [4., 6., 8. ]])
vec2 = (np.pi/4) * vec1
vec3 = np.cos( vec2 )
print(vec2, vec3)
# Output
# [-0.78539816 3.14159265 -7.06858347] [ 0.70710678 -1. 0.70710678]
Comments
Leave a comment