0
0
NumPydata~10 mins

np.linalg.det() for determinant in NumPy - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to calculate the determinant of matrix A.

NumPy
import numpy as np
A = np.array([[1, 2], [3, 4]])
det = np.linalg.[1](A)
print(det)
Drag options to blanks, or click blank then click option'
Adeterminant_value
Bdeterminant
Cdet
Ddetermin
Attempts:
3 left
💡 Hint
Common Mistakes
Using a wrong function name like 'determinant' or 'determin'.
Trying to call determinant as an attribute instead of a function.
2fill in blank
medium

Complete the code to create a 3x3 matrix and calculate its determinant.

NumPy
import numpy as np
B = np.array([[1, 0, 2], [0, 1, 0], [3, 0, 1]])
det_B = np.linalg.[1](B)
print(det_B)
Drag options to blanks, or click blank then click option'
Adet
Bdeterminant
Cdeterminant_value
Ddetermin
Attempts:
3 left
💡 Hint
Common Mistakes
Using a non-square matrix which causes an error.
Using a wrong function name.
3fill in blank
hard

Fix the error in the code to correctly compute the determinant of matrix C.

NumPy
import numpy as np
C = np.array([[2, 5], [1, 3]])
det_C = np.linalg.[1](C)
print(det_C)
Drag options to blanks, or click blank then click option'
Adeterminant
Bdetermin
Cdeterminant_value
Ddet
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'determinant' instead of 'det'.
Misspelling the function name.
4fill in blank
hard

Fill both blanks to create a 2x2 matrix and calculate its determinant.

NumPy
import numpy as np
matrix = np.array([[[1], [2]], [4, 5]])
det_matrix = np.linalg.det(matrix)
print(det_matrix)
Drag options to blanks, or click blank then click option'
A1
B2
C3
D6
Attempts:
3 left
💡 Hint
Common Mistakes
Using non-numeric values in the matrix.
Creating a non-square matrix.
5fill in blank
hard

Fill all three blanks to create a 3x3 matrix and calculate its determinant.

NumPy
import numpy as np
M = np.array([[[1], 0, 0], [0, [2], 0], [0, 0, [3]]])
det_M = np.linalg.det(M)
print(det_M)
Drag options to blanks, or click blank then click option'
A2
B3
C4
D5
Attempts:
3 left
💡 Hint
Common Mistakes
Filling non-diagonal elements with non-zero values.
Using incorrect diagonal values.