Numpy is Python module that is used for array creation, modification and creating sub arrays for numpy arrays.
Concatenation of arrays
- Concatenate:-
It will concatenate two arrays and gives the output as one array. Let us see by code:-
Concatenate 3 or more arrays:-
we can concatenate as any array we want. Let us talk, where the case of 3 arrays, we will concatenate all the 3 arrays
Concatenation of same array:-
We can also concatenate same array together. Like we can concatenate x + x.
Let's see the Code:-
NOTE:- point here to be noted that, the arguments should be passed in [] brackets only.
np.concatenate([x, y])
2-D or multidimensional Array Concatenation:-
We can also concatenate the 2-D array or multidimensional array as well.
Let us see the code where we concatenate 2-D array.
Code:-
By default is concatenate on the row but we can set its axis to 1 so that it can concatenate column-wise.
Code:-
What is np.vstack?
Numpy provides concatenation vertically on 2D and multidimensional array. np.vstack concatenate array vertically.
Let us see by example:-
NOTE:- Point here to be noted that in np.vstack there should be same length of columns regardless of the rows.
What is np.hstack?
np.hstack provides the concatenation of the array horizontally. It will compare if both have same length of the row or not regardless of the size of columns. If the size of the row mismatch, it willl throw an array.
Code:-
I hope you can understand by our methods. Please Subscribe to our Youtube channel
If you want to learn Data Science in hindi, you can go through our channel. We are creating Data Science Tutorial.
Codin India - India towards Digitalization
Thanks to be here
Comments
Post a Comment