Subtitles section Play video Print subtitles Hello everyone, a warm welcome to you. In today's video, we are going to see how to stock two arrays in NumPy. So as you know, in NumPy, the arrays are the object, right? So if two arrays are given, how to stock those arrays or how to combine those two arrays. So we have few functions in NumPy for that. So let's see how to do it. So first, let me create two arrays. I'm importing NumPy. And let me create two arrays here. Let's take an object as AR1. And AR2. So using array function, I'm creating two arrays here. So here we have AR1 and AR2, two one-dimensional arrays, right? And if I wanted to combine these two arrays, I can use stock function. So first, let me show you how to use stock function for that. So let's say stock and I need to pass both the arrays inside this function. So this will combine these two arrays, right? So as you can see, it combines these two arrays row wise. And I have given both one-dimensional array in the stock function. And if you see the output, it has returned as two dimension, right? So if you check the shape of this, you can see that we have two dimension array here, right? So by default, this function combines row wise. But let's say if I wanted to combine it column wise, then still I can use this function. And there is a parameter called axis. So I can include this parameter where I can give as one. So by default, this parameter will take value as zero, which refers to rows, okay? When axis is zero, it refers to rows and when axis is one, it refers to columns. So here, if I try to combine these two arrays using stock function by giving axis as one, you can see that these two arrays are combined column wise, right? So you can use stock function to combine two arrays, okay? And now let's see the other function like vstock. So here I'm going to call this vstock. So vstock stands for vertical stock, okay? If you wanted to combine two arrays vertically, right? So you can use this vstock and let me pass both the arrays inside this function. So here it gives you again, if you see both are one dimensional array and the output which you got is a two dimensional array, right? So if you check the shape of it, you can see it's two dimension, right? So vstock gives you, it takes two one dimensional array and gives you a two dimensional array where it combines them vertically, right? And if you wanted to combine or stack the array horizontally, then we have function for that called hstock. So again, I'm going to pass both these arrays. And you can see that the two arrays are stacked horizontally, right? And you can see that it's one dimensional array. So hstock by default gives you it when it takes two one dimensional array, it gives you one dimensional array as the output, right? So these are the difference between stock, vstock and hstock. So you can stack two arrays using these functions. Thank you.
B2 US array dimensional numpy stock combine axis Stack, Vstack and Hstack | Numpy Stack functions | Python Numpy Tutorial 11 0 鄭力瑋 posted on 2024/07/07 More Share Save Report Video vocabulary