A matrix is a rectangular grid of numbers arranged in rows and columns. It is used to organize data and perform mathematical operations like addition, multiplication, and finding determinants.
Click to reveal answer
beginner
How do you create a 3x3 matrix using SciPy?
You can create a 3x3 matrix using <code>scipy.sparse</code> or <code>numpy</code>. For example, with NumPy: <br><code>import numpy as np<br>matrix = np.array([[1,2,3],[4,5,6],[7,8,9]])</code>
Click to reveal answer
intermediate
What is matrix multiplication and when is it used?
Matrix multiplication combines two matrices to produce a new matrix. It is used in data transformations, solving systems of equations, and machine learning algorithms.
Click to reveal answer
beginner
How can you find the transpose of a matrix in SciPy or NumPy?
The transpose flips a matrix over its diagonal. In NumPy, use matrix.T. In SciPy sparse matrices, use matrix.transpose().
Click to reveal answer
intermediate
What is the difference between dense and sparse matrices?
Dense matrices store all elements explicitly, even zeros. Sparse matrices store only non-zero elements to save memory and speed up calculations when many elements are zero.
Click to reveal answer
Which function creates a 2x2 identity matrix in NumPy?
Anp.eye(3)
Bnp.identity(2)
Cnp.ones((2,2))
Dnp.zeros((2,2))
✗ Incorrect
np.identity(2) creates a 2x2 identity matrix with ones on the diagonal and zeros elsewhere.
What is the result of multiplying a 2x3 matrix by a 3x2 matrix?
AA 2x2 matrix
BA 3x3 matrix
CA 2x3 matrix
DAn error
✗ Incorrect
Matrix multiplication of a 2x3 and 3x2 matrix results in a 2x2 matrix.
Which method transposes a sparse matrix in SciPy?
Amatrix.transpose()
Bmatrix.T
Cmatrix.swap()
Dmatrix.flip()
✗ Incorrect
In SciPy sparse matrices, use matrix.transpose() to get the transpose.
Why use sparse matrices instead of dense matrices?
ATo make matrices denser
BTo increase matrix size
CTo avoid matrix multiplication
DTo save memory when many elements are zero
✗ Incorrect
Sparse matrices save memory and speed up calculations by storing only non-zero elements.
Which library is commonly used for matrix operations in Python?
ARequests
BPandas
CNumPy
DMatplotlib
✗ Incorrect
NumPy is the main library for numerical and matrix operations in Python.
Explain how to create and multiply two matrices using SciPy or NumPy.
Think about how rows and columns must match for multiplication.
You got /3 concepts.
Describe the advantages of using sparse matrices in data science.
Consider when many matrix elements are zero.
You got /3 concepts.
Practice
(1/5)
1. What does the scipy.linalg.inv() function do when applied to a square matrix?
easy
A. Transposes the matrix
B. Calculates the determinant of the matrix
C. Calculates the inverse of the matrix
D. Creates a zero matrix of the same size
Solution
Step 1: Understand the function purpose
The scipy.linalg.inv() function is designed to find the inverse of a square matrix if it exists.
Step 2: Differentiate from other matrix operations
Determinant calculation uses scipy.linalg.det(), transpose uses .T, and zero matrix creation uses numpy.zeros().
Final Answer:
Calculates the inverse of the matrix -> Option C
Quick Check:
Inverse = inv() [OK]
Hint: Inverse means flipping matrix; use inv() for that [OK]
Common Mistakes:
Confusing inverse with determinant
Thinking inv() transposes matrix
Assuming inv() creates zero matrix
2. Which of the following is the correct way to create a 3x3 identity matrix using NumPy?
easy
A. scipy.identity(3)
B. scipy.eye(3)
C. scipy.linalg.eye(3)
D. np.identity(3)
Solution
Step 1: Identify the correct module and function
The identity matrix function is in numpy (imported as np) as identity().
Step 2: Check other options for correctness
scipy.eye() and scipy.linalg.eye() do not exist; scipy.identity() is not valid.
Final Answer:
np.identity(3) -> Option D
Quick Check:
Identity matrix = np.identity() [OK]
Hint: Use np.identity() for identity matrix [OK]
Common Mistakes:
Using scipy.eye() which does not exist
Calling identity() from wrong module
Confusing identity with eye from numpy
3. What is the output of the following code?
import numpy as np
from scipy.linalg import det
A = np.array([[1, 2], [3, 4]])
print(round(det(A), 2))
medium
A. -2.00
B. 2.00
C. 10.00
D. -10.00
Solution
Step 1: Calculate determinant of matrix A
Determinant formula for 2x2 matrix [[a,b],[c,d]] is ad - bc = 1*4 - 2*3 = 4 - 6 = -2.
Step 2: Round the result to 2 decimals
Rounding -2 to 2 decimals remains -2.00.
Final Answer:
-2.00 -> Option A
Quick Check:
Determinant = -2.00 [OK]
Hint: Determinant 2x2 = ad - bc [OK]
Common Mistakes:
Calculating ad + bc instead of ad - bc
Forgetting negative sign
Not rounding output
4. Identify the error in this code snippet:
import numpy as np
from scipy.linalg import inv
B = np.array([[1, 2], [2, 4]])
B_inv = inv(B)
print(B_inv)
medium
A. Matrix B is singular and cannot be inverted
B. Syntax error in array creation
C. inv() function is not imported correctly
D. Matrix B is not square
Solution
Step 1: Check matrix properties
Matrix B is square (2x2), but rows are linearly dependent (second row is twice the first).
Step 2: Understand invertibility
Such a matrix is singular (determinant zero), so inverse does not exist, causing an error when calling inv().
Final Answer:
Matrix B is singular and cannot be inverted -> Option A
Quick Check:
Singular matrix = no inverse [OK]
Hint: Check determinant; zero means no inverse [OK]
Common Mistakes:
Thinking non-square matrix causes error here
Assuming inv() import is wrong
Missing linear dependence in matrix
5. You have two matrices:
M = np.array([[1, 2], [3, 4]])
N = np.array([[2, 0], [1, 2]])
Which code correctly computes the product P = M x N using scipy?
hard
A. from scipy.linalg import dot
P = dot(M, N)
B. import numpy as np
P = np.dot(M, N)
C. from scipy.linalg import matmul
P = matmul(M, N)
D. from scipy.linalg import inv
P = inv(M) * N
Solution
Step 1: Identify correct matrix multiplication function
Scipy.linalg does not have dot or matmul functions; numpy provides np.dot() for matrix multiplication.
Step 2: Check options for correctness
import numpy as np
P = np.dot(M, N) uses np.dot(M, N) which correctly multiplies matrices M and N. from scipy.linalg import inv
P = inv(M) * N incorrectly uses inverse and element-wise multiplication.
Final Answer:
import numpy as np
P = np.dot(M, N) -> Option B
Quick Check:
Matrix product = np.dot() [OK]
Hint: Use np.dot() for matrix multiplication [OK]
Common Mistakes:
Using inv() instead of multiplication
Assuming scipy.linalg has dot or matmul
Using * for matrix multiplication
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.