In NumPy, you can join 2 or more arrays together using np.concatenate
. To do so, you will need to ensure that if you are adding a row, the rows of both arrays must be the same. Likewise for columns.
Syntax
np.concatenate(array1, array2)
Once again we start by creating some arrays with .arange
Arrays can be stacked horizontally - meaning that you can join the arrays by the sides. To do this, we need to ensure that the number of rows in all arrays that are to be joined together are the same.
Arrays can be also be stacked vertically - meaning that you can join the arrays by the top / bottom. To do this, we need to ensure that the number of columns in all arrays that are to be joined together are the same.
Rearrange the following arrays and stack them vertically with 5 columns:
myArray_1 = np.arange(20) myArray_2 = np.arange(30)
Your results should look like this:
[[ 0 1 2 3 4] [ 5 6 7 8 9] [10 11 12 13 14] [15 16 17 18 19] [ 0 1 2 3 4] [ 5 6 7 8 9] [10 11 12 13 14] [15 16 17 18 19] [20 21 22 23 24] [25 26 27 28 29]]
You are expected to comply with University policies and guidelines namely, Appropriate Use of Information Resources Policy, IT Usage Policy and Social Media Policy. Users will be personally liable for any infringement of Copyright and Licensing laws. Unless otherwise stated, all guide content is licensed by CC BY-NC 4.0.