Bird
Raised Fist0
SciPydata~10 mins

Matrix determinant (det) in SciPy - Interactive Code Practice

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

Complete the code to import the function that calculates the determinant of a matrix.

SciPy
from scipy.linalg import [1]

matrix = [[1, 2], [3, 4]]
result = det(matrix)
print(result)
Drag options to blanks, or click blank then click option'
Adet
Bdeterminant
Cdetermin
Ddeterminant_calc
Attempts:
3 left
💡 Hint
Common Mistakes
Using a wrong function name like 'determinant' which does not exist in scipy.linalg.
Trying to import from numpy.linalg instead of scipy.linalg.
2fill in blank
medium

Complete the code to calculate the determinant of the given matrix.

SciPy
from scipy.linalg import det

matrix = [[2, 3], [1, 4]]
determinant = [1](matrix)
print(determinant)
Drag options to blanks, or click blank then click option'
Adet_calc
Bdet
Cdetermin
Ddeterminant
Attempts:
3 left
💡 Hint
Common Mistakes
Calling a function that is not imported or does not exist.
Trying to call 'determinant' which is not defined.
3fill in blank
hard

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

SciPy
from scipy.linalg import det

matrix = [[1, 2, 3], [4, 5, 6]]
det_value = [1](matrix)
print(det_value)
Drag options to blanks, or click blank then click option'
Adetermin
Bdeterminant
Cdet_calc
Ddet
Attempts:
3 left
💡 Hint
Common Mistakes
Using a wrong function name.
Trying to calculate determinant of a non-square matrix (which causes runtime error).
4fill in blank
hard

Fill both blanks to create a dictionary of determinants for matrices with size 2 and 3.

SciPy
from scipy.linalg import det

matrices = {
    2: [[1, 2], [3, 4]],
    3: [[1, 0, 2], [0, 1, 5], [3, 2, 1]]
}
determinants = {size: det([1]) for size, [2] in matrices.items()}
print(determinants)
Drag options to blanks, or click blank then click option'
Amatrix
Bmat
Cmatrixes
Dm
Attempts:
3 left
💡 Hint
Common Mistakes
Using the key instead of the value for determinant calculation.
Using variable names not matching the iteration unpacking.
5fill in blank
hard

Fill all three blanks to create a dictionary comprehension that stores determinants of matrices with keys as uppercase size names.

SciPy
from scipy.linalg import det

matrices = {
    'two': [[2, 0], [0, 2]],
    'three': [[1, 2, 3], [0, 1, 4], [5, 6, 0]]
}
determinants = [1]([2].upper(): [3](matrix) for [2], matrix in matrices.items())
print(determinants)
Drag options to blanks, or click blank then click option'
Adict
Bkey
Cdet
Dvalue
Attempts:
3 left
💡 Hint
Common Mistakes
Using the same variable name for both key and value in the comprehension.
Not converting the key to uppercase.
Using a wrong function name for determinant.

Practice

(1/5)
1. What does the determinant of a square matrix tell us in simple terms?
easy
A. If the matrix can be reversed or undone
B. The number of rows in the matrix
C. The sum of all elements in the matrix
D. The largest value in the matrix

Solution

  1. Step 1: Understand determinant meaning

    The determinant helps us know if a matrix can be inverted or reversed.
  2. Step 2: Relate to matrix properties

    If the determinant is zero, the matrix cannot be inverted; otherwise, it can.
  3. Final Answer:

    If the matrix can be reversed or undone -> Option A
  4. Quick Check:

    Determinant shows invertibility [OK]
Hint: Determinant zero means no inverse [OK]
Common Mistakes:
  • Confusing determinant with matrix size
  • Thinking determinant is sum of elements
  • Assuming determinant gives max value
2. Which of the following is the correct way to import the determinant function from scipy?
easy
A. from scipy import determinant
B. from scipy.linalg import det
C. import scipy.det
D. import det from scipy.linalg

Solution

  1. Step 1: Recall scipy.linalg module usage

    The determinant function is in scipy.linalg and is named det.
  2. Step 2: Check correct import syntax

    Python import syntax for a function is: from module import function.
  3. Final Answer:

    from scipy.linalg import det -> Option B
  4. Quick Check:

    Correct import syntax for det [OK]
Hint: Use 'from scipy.linalg import det' to import [OK]
Common Mistakes:
  • Using wrong module name
  • Incorrect import syntax
  • Trying to import non-existent names
3. What is the output of this code?
import numpy as np
from scipy.linalg import det
A = np.array([[2, 3], [1, 4]])
print(round(det(A), 2))
medium
A. 14.0
B. 10.0
C. 11.0
D. 5.0

Solution

  1. Step 1: Calculate determinant manually

    For matrix [[2,3],[1,4]], determinant = (2*4) - (3*1) = 8 - 3 = 5.
  2. Step 2: Confirm code output

    Code prints determinant rounded to 2 decimals, so output is 5.0.
  3. Final Answer:

    5.0 -> Option D
  4. Quick Check:

    Determinant = 5.0 [OK]
Hint: Det = ad - bc for 2x2 matrix [OK]
Common Mistakes:
  • Mixing multiplication order
  • Not rounding output
  • Confusing matrix elements
4. Identify the error in this code snippet:
import numpy as np
from scipy.linalg import det
B = np.array([[1, 2, 3], [4, 5, 6]])
print(det(B))
medium
A. Matrix B is not square, so det() will raise an error
B. Missing import for numpy
C. det() function is misspelled
D. No error, code runs fine

Solution

  1. Step 1: Check matrix shape

    Matrix B has shape (2,3), which is not square.
  2. Step 2: Understand det() requirements

    det() requires a square matrix; otherwise, it raises a LinAlgError.
  3. Final Answer:

    Matrix B is not square, so det() will raise an error -> Option A
  4. Quick Check:

    det() needs square matrix [OK]
Hint: Only square matrices have determinants [OK]
Common Mistakes:
  • Ignoring matrix shape
  • Assuming det works on any matrix
  • Overlooking error messages
5. You have a 3x3 matrix:
M = np.array([[1, 2, 3], [0, 1, 4], [5, 6, 0]])

Using scipy.linalg.det, what is the determinant of M? Choose the closest value rounded to 2 decimals.
hard
A. -24.00
B. 31.00
C. 1.00
D. -79.00

Solution

  1. Step 1: Calculate determinant manually

    Calculate determinant of M:
    det(M) = 1*(1*0 - 4*6) - 2*(0*0 - 4*5) + 3*(0*6 - 1*5)
    = 1*(0 - 24) - 2*(0 - 20) + 3*(0 - 5)
    = -24 + 40 - 15 = 1
  2. Step 2: Confirm with scipy.linalg.det

    Using det(M) in code returns 1.0, rounded to 2 decimals is 1.00.
  3. Final Answer:

    1.00 -> Option C
  4. Quick Check:

    Determinant = 1.00 [OK]
Hint: Use cofactor expansion for 3x3 determinant [OK]
Common Mistakes:
  • Wrong sign in cofactor terms
  • Mixing row and column indices
  • Forgetting to round result
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard