Define the following vectors and matrices:
vec1 = np.array([ -1., 4., -9.])
mat1 = np.array([[ 1., 3., 5.], [7., -9., 2.], [4., 6., 8. ]]
10. What function would you use to find the value of j so that vec1[j] is equal to the smallest element in vec1?
11. What expression would you use to find the smallest element of the matrix
mat1?
import numpy as np
vec1 = np.array([ -1., 4., -9.])
mat1 = np.array([[ 1., 3., 5.], [7., -9., 2.], [4., 6., 8. ]])
#function vec1.argmin() returns the index of the smallest element in the vec1 array
j = vec1.argmin()
#expression mat1.min() returns the value of the smallest element in the mat1 array
smallest = mat1.min()
print(j)
print(smallest)
Comments
Leave a comment