Define the following vectors and matrices:
vec1 = np.array([ -1., 4., -9.])
mat1 = np.array([[ 1., 3., 5.], [7., -9., 2.], [4., 6., 8. ]]
13. The function np.random.rand can be used to construct and fill vectors and matrices with random numbers. Use the help facility in Python to learn how to construct a 10 × 10 matrix named M filled with random numbers.
# importing numpy library
import numpy as np
vec1 = np.array([ -1., 4., -9.])
# vec1 is row vector displayed as 1 dimensional array
mat1 = np.array([[ 1., 3., 5.], [7., -9., 2.], [4., 6., 8. ]])
# mat1 is a square matrix with dimension of 3x3 where in each of 3 row contain 3 values
#construct a 10 × 10 matrix
M = np.random.rand(10, 10)
print(M)
Comments
Leave a comment