Lesson 5 ❮ Lesson List ❮ Top Page
❯ 5.4 Join, Split, and Transpose
⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺
EXPECTED COMPLETION TIME
❲▹❳ Video 5m 34s
☷ Interactive readings 5m
✑ Practice 5.4 (G Colab) 20m
Joining means putting contents of two or more arrays in a single array.
np.concatenate((arr1, arr2, ...))
joins arr1, arr2, ..., along with the axis. If axis is not explicitly passed, it is taken as 0.
Splitting is the reverse operation of Joining. It breaks one array into multiple.
np.array_split(arr, num)
split arr into num sub-arrays. It will return a list object (not ndarray).
Stacking is the same as concatenation, the only difference is that stacking is done along a new axis.
We can concatenate two 1-D arrays along the second axis which would result in putting them one over the other, ie. stacking.
np.vstack([arr1, arr2, ...])
stack arr1, arr2, ..., in sequence vertically (row wise).
np.hstack([arr1, arr2, ...])
stack arr1, arr2, ..., in sequence horizontally (column wise).
Swapping axes can be necessary to form the data into a better format. This can be done by transposing the array.
np.transpose(arr)
reverse the axes of arr and returns the modified array.