0
0
NumPydata~5 mins

transpose() for swapping axes in NumPy - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
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?
AAdds a new axis
BFlattens the array
CDeletes the array
DSwaps rows and columns
How do you swap the first and second axes of a 3D array arr using transpose()?
A<code>arr.transpose(1, 0, 2)</code>
B<code>arr.transpose(0, 2, 1)</code>
C<code>arr.transpose(2, 1, 0)</code>
D<code>arr.transpose()</code>
Which attribute is a shortcut for transpose() on 2D arrays?
A<code>.T</code>
B<code>.shape</code>
C<code>.reshape</code>
D<code>.flatten</code>
If you have a 2D array with shape (3, 5), what shape will it have after transpose()?
A(15,)
B(3, 5)
C(5, 3)
D(1, 15)
Why might you want to swap axes in a dataset?
ATo encrypt data
BTo change how data is organized for analysis or visualization
CTo increase the size of data
DTo delete data
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.