Jump into concepts and practice - no test required
or
Recommended
Test this pattern10 questions across easy, medium, and hard to know if this pattern is strong
Recall & Review
beginner
What does the transpose of a matrix do?
It flips the matrix over its diagonal, switching the row and column indices of each element.
Click to reveal answer
beginner
How do you transpose a matrix using NumPy?
Use the .T attribute on a NumPy array, like matrix.T.
Click to reveal answer
beginner
What is the shape of the transpose of a matrix with shape (3, 5)?
The transpose will have shape (5, 3), swapping rows and columns.
Click to reveal answer
beginner
True or False: Transposing a matrix twice returns the original matrix.
True. Transposing twice flips the matrix back to its original form.
Click to reveal answer
intermediate
How can you transpose a 3D NumPy array along specific axes?
Use np.transpose(array, axes=(...)) to reorder axes as needed.
Click to reveal answer
What does matrix.T do in NumPy?
AReturns the matrix multiplied by 2
BReturns the inverse of the matrix
CReturns the determinant of the matrix
DReturns the transpose of the matrix
✗ Incorrect
matrix.T flips the matrix over its diagonal, swapping rows and columns.
If a matrix has shape (4, 7), what is the shape of its transpose?
A(7, 4)
B(4, 7)
C(1, 28)
D(28, 1)
✗ Incorrect
Transposing swaps rows and columns, so (4, 7) becomes (7, 4).
Which NumPy function allows transposing with custom axis order?
Anp.transpose()
Bnp.reshape()
Cnp.flatten()
Dnp.dot()
✗ Incorrect
np.transpose() lets you specify axes order for transposing arrays.
What happens if you transpose a matrix twice?
AYou get the inverse matrix
BYou get a zero matrix
CYou get the original matrix
DYou get a matrix with doubled values
✗ Incorrect
Transposing twice returns the matrix to its original form.
Which of these is NOT true about matrix transpose?
AIt swaps rows and columns
BIt multiplies each element by -1
CIt flips the matrix over its diagonal
DIt changes the shape of the matrix
✗ Incorrect
Transpose does not change element values, only their positions.
Explain how to transpose a 2D matrix in NumPy and describe what happens to its shape.
Think about flipping the matrix over its diagonal.
You got /3 concepts.
Describe how to transpose a 3D NumPy array along specific axes and why this might be useful.
Consider how axes represent dimensions in arrays.
You got /3 concepts.
Practice
(1/5)
1. What does the .T attribute do when applied to a NumPy matrix?
easy
A. It flips the rows and columns of the matrix (transpose).
B. It multiplies all elements by 2.
C. It returns the sum of all elements.
D. It flattens the matrix into a 1D array.
Solution
Step 1: Understand the .T attribute
The .T attribute in NumPy returns the transpose of a matrix, which means rows become columns and columns become rows.
Step 2: Compare with other options
Multiplying by 2, summing elements, or flattening are different operations and not related to .T.
Final Answer:
It flips the rows and columns of the matrix (transpose). -> Option A
Quick Check:
Transpose = flip rows and columns [OK]
Hint: Remember: .T flips rows and columns [OK]
Common Mistakes:
Confusing transpose with flattening
Thinking .T multiplies elements
Assuming .T sums elements
2. Which of the following is the correct syntax to transpose a NumPy array named arr?
easy
A. arr.transpose
B. arr.T()
C. transpose(arr)
D. arr.T
Solution
Step 1: Recall NumPy transpose syntax
In NumPy, .T is an attribute, not a method, so it does not use parentheses.
Step 2: Evaluate each option
arr.transpose() uses transpose() method which exists but is a method, so requires parentheses. arr.T() incorrectly uses .T() as a method. transpose(arr) is not valid syntax. arr.T correctly uses .T attribute without parentheses.
Final Answer:
arr.T -> Option D
Quick Check:
Transpose attribute = arr.T [OK]
Hint: Use .T without parentheses to transpose [OK]
Transposing swaps rows and columns, so the first row [1, 2] becomes the first column, and the second row [3, 4] becomes the second column. Result: [[1, 3], [2, 4]].
B. Using parentheses with .T attribute causes an error.
C. Missing import statement for numpy.
D. print() function is used incorrectly.
Solution
Step 1: Check usage of .T
The .T attribute is not a function, so it should not have parentheses. Using .T() causes a TypeError.
Step 2: Verify other parts of the code
Array creation and import are correct. The print statement is also correct.
Final Answer:
Using parentheses with .T attribute causes an error. -> Option B
Quick Check:
.T is attribute, not method [OK]
Hint: Do not add () after .T attribute [OK]
Common Mistakes:
Calling .T as a function with ()
Assuming .T needs import
Thinking print syntax is wrong
5. You have a 3x2 NumPy array arr = np.array([[1, 2], [3, 4], [5, 6]]). You want to multiply it by another array so that the result is a 2x2 matrix. Which of the following correctly uses transpose to achieve this multiplication?
import numpy as np
arr = np.array([[1, 2], [3, 4], [5, 6]])
arr2 = ???
result = np.dot(arr.T, arr2)
print(result)
arr is 3x2. Its transpose arr.T is 2x3. For matrix multiplication np.dot(arr.T, arr2), the number of rows in arr2 must be 3 to match arr.T's columns.
Step 2: Check options for correct shape
arr2 = np.array([[1, 0], [0, 1], [1, 1]]) shape is 3x2, so arr.T (2x3) dot arr2 (3x2) results in 2x2 matrix, which is valid. arr2 = np.array([[1, 0], [0, 1]]) shape is 2x2, which does not match for multiplication with 2x3. arr2 = np.array([[1, 0, 1], [0, 1, 1]]) shape is 2x3, which does not match. arr2 = np.array([[1, 0], [0, 1], [1, 1], [0, 0]]) shape is 4x2, invalid.