Recall & Review
beginner
What does the
transpose() function do in NumPy?It swaps the axes of an array, effectively flipping its dimensions. For example, it turns rows into columns and vice versa.
Click to reveal answer
beginner
How do you use
transpose() to swap the first and second axes of a 2D array?You can call
array.transpose() without arguments to swap the two axes of a 2D array.Click to reveal answer
intermediate
What is the difference between
transpose() and .T in NumPy?.T is a shortcut for transpose() on arrays of two or more dimensions. Both swap axes, but transpose() can take arguments to reorder axes in higher dimensions.Click to reveal answer
intermediate
How can you use
transpose() to reorder axes in a 3D array?You pass a tuple with the new order of axes to
transpose(). For example, array.transpose(1, 0, 2) swaps the first two axes but keeps the third the same.Click to reveal answer
beginner
Why is swapping axes useful in data science?
Swapping axes helps reshape data to fit algorithms, visualize data differently, or prepare data for operations that expect a certain shape.
Click to reveal answer
What does
array.transpose() do to a 2D NumPy array?✗ Incorrect
transpose() swaps the rows and columns of a 2D array.
How do you swap the first and second axes of a 3D array
arr using transpose()?✗ Incorrect
Passing (1, 0, 2) swaps the first two axes and keeps the third axis unchanged.
Which attribute is a shortcut for
transpose() on 2D arrays?✗ Incorrect
.T is a quick way to transpose 2D arrays.
If you have a 2D array with shape (3, 5), what shape will it have after
transpose()?✗ Incorrect
Transpose swaps the axes, so (3, 5) becomes (5, 3).
Why might you want to swap axes in a dataset?
✗ Incorrect
Swapping axes helps organize data in a way that fits your analysis or visualization needs.
Explain in your own words what
transpose() does to a NumPy array and give a simple example.Think about rows and columns switching places.
You got /3 concepts.
Describe how you would use
transpose() to reorder axes in a 3D array and why this might be useful.Consider how data shape affects analysis.
You got /3 concepts.