Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use the numpy.concatenate () function

2025-01-15 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/02 Report--

This article mainly introduces "the use of the numpy.concatenate () function". In the daily operation, I believe that many people have doubts about the use of the numpy.concatenate () function. The editor consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful to answer the doubts about the use of the numpy.concatenate () function. Next, please follow the editor to study!

The numpy.concatenate () function accepts an array of dimensions whose shapes must be the same except for the dimensions on the concatenation.

Experiment:

Python 3.7.4 (tags/v3.7.4:e09359112e, Jul 8 2019, 20:34:20) [MSC v.1916 64 bit (AMD64)] on win32Type "help", "copyright", "credits" or "license ()" for more information. > > import numpy as np > > a = np.array ([[1,2], [3,4]) > > b = np.array ([[5,6])) > > aarray ([[1,2], [3,4]]) > > barray ([[5]) ) > a.shape (2,2) > b.shape (1,2) > np.concatenate ((a, b), axis=0) array ([[1,2], [3,4], [5,6]]) > np.concatenate ((a, b), axis=0) .shape (3,2) > np.concatenate ((a, b.T), axis=1) array ([[1,2,5], [3,4,6])) > if the passed parameter axis=None So it means to develop into an one-dimensional splicing > np.concatenate ((a, b), axis=None) array > a = np.zeros > b = np.zeros ((2p3) > a.shape) > b.shape > np.concatenate (a, b), axis=3) .shape (2p3PM6, axis=3). 6) > np.concatenate ((a, b), axis=2) Traceback (most recent call last): File ", line 1, in np.concatenate ((a, b), axis=2) File", line 6, in concatenateValueError: all the input array dimensions for the concatenation axis must match exactly, but along dimension 3, the array at index 0 has size 5 and the array at index 1 has size 7 > # except for the spliced parts, the shape of the rest must be the same > The study on "how to use the numpy.concatenate () function" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report