0
0
NumPydata~5 mins

np.concatenate() for joining arrays in NumPy - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What does np.concatenate() do in NumPy?

np.concatenate() joins two or more arrays into one bigger array along a specified axis.

Click to reveal answer
beginner
What is the default axis for np.concatenate()?

The default axis is axis=0, which means arrays are joined row-wise (stacked vertically).

Click to reveal answer
beginner
Can np.concatenate() join arrays of different shapes?

No, arrays must have the same shape except in the dimension along the joining axis.

Click to reveal answer
beginner
How do you join two 1D arrays a = [1, 2] and b = [3, 4] using np.concatenate()?

Use np.concatenate([a, b]) to get [1, 2, 3, 4].

Click to reveal answer
intermediate
What happens if you set axis=1 when concatenating 2D arrays?

Arrays are joined column-wise (side by side), increasing the number of columns.

Click to reveal answer
What is the result of np.concatenate([np.array([1,2]), np.array([3,4])])?
A[[1 2] [3 4]]
B[[1 3] [2 4]]
C[1 2 3 4]
DError
Which axis joins arrays side by side (columns) in 2D with np.concatenate()?
Aaxis=1
Baxis=-1
Caxis=0
Daxis=2
If two arrays have shapes (2,3) and (2,4), can they be concatenated along axis=0?
AYes
BNo
COnly if axis=1
DOnly if reshaped
What type of object must be passed to np.concatenate()?
AA scalar value
BA single array
CA dictionary
DA list or tuple of arrays
What happens if arrays have different shapes on non-concatenation axes?
AAn error is raised
BThey concatenate successfully
CArrays are padded automatically
DArrays are truncated
Explain how np.concatenate() works and what rules arrays must follow to be joined.
Think about stacking arrays like stacking blocks either vertically or horizontally.
You got /4 concepts.
    Describe a real-life example where you might use np.concatenate() to combine data.
    Imagine putting together pieces of a puzzle to see the full picture.
    You got /4 concepts.