This time I will bring you Python's numpyarraysHow to merge, what are the notes for Python's numpy array merge, the following is a practical case, Let’s take a look.
There are many ways to merge numpy arrays in Python, such as
- np.append()
- np.concatenate()
- np.stack()
- np.hstack()
- np.vstack()
- np.dstack()
The most commonly used one is the first one and the second. The first one is more readable and flexible, but takes up a lot of memory. The second one does not have the problem of large memory usage.
Method 1——append
introduction | |
---|---|
Copy of the array to be merged (especially the homepage is | copy, so it will consume a lot more memory) |
Used to merge the copied values into the above array. If the following parameters | axis are specified, these values must be consistent with the shape of arr (equal except shape[axis]), otherwise, there is no requirement.
|
Axis to be merged |
Example:
Method 2——concatenate
introduction | |
---|---|
sThese arrays are except on the axis to be merged (the default is axis=0) In addition, it must have the same shape | |
The axis to be merged, the default is 0 |
I believe you have mastered the method after reading the case in this article. For more exciting information, please pay attention to other related articles on the php Chinese website!
Recommended reading:
Summary of Pycharm usage skillsHow to obtain the local peak value of a two-dimensional array in pythonThe above is the detailed content of How to merge numpy arrays in Python. For more information, please follow other related articles on the PHP Chinese website!