Home >Backend Development >Python Tutorial >How to merge numpy arrays in Python

How to merge numpy arrays in Python

php中世界最好的语言
php中世界最好的语言Original
2018-04-09 15:42:324276browse

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

##parametersintroductionarrCopy of the array to be merged (especially the homepage is values Used to merge the copied values ​​into the above array. If the following parameters axisAxis to be merged
copy, so it will consume a lot more memory)
axis are specified, these values ​​​​must be consistent with the shape of arr (equal except shape[axis]), otherwise, there is no requirement.

Example:

Method 2——concatenate

##parameters*arrayaxis
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
Example:

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 skills


How to obtain the local peak value of a two-dimensional array in python

The 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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn