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-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

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

This article mainly shows you "how to use the numpy.concatenate () function", the content is easy to understand, clear, hope to help you solve your doubts, let the editor lead you to study and learn "how to use the numpy.concatenate () function" this article.

Numpy.concatenate ((A1, a2, …) , axis=0, out=None)

Combine array sequences with the same structure into an array

Axis is the splicing direction, 0 is the horizontal axis, 1 is the vertical axis.

Axis=0, the splicing direction is the horizontal axis, which requires the same vertical axis structure, and the splicing direction can be understood as the direction in which the quantity changes after the splicing is completed.

> a=np.array > > b=np.array ([11pyrrine 22]) > c=np.array ([44recorder 55pence66]) > np.concatenate (ameme brecric), axis=0) # by default, axis=0 can not write array ([1MIT 2p3, 11pr 2233,44PM 55566]) # for one-dimensional array stitching The value of axis does not affect the final result > a=np.array > > b=np.array ([[11pr 21,8]]) > np.concatenate ((aprit b), axis=0) array ([[1je 2men3], [4pr 5recorder 6], [11pr 2l 31], [7come8]) > np.concatenate ((aPowerb)) Axis=1) # axis=1 represents an array of corresponding rows for splicing array ([1, 2, 3, 11, 21, 31], [4, 5, 6, 7, 8, 9]) > import numpy as np > a = np.array ([[1, 2], [3, 4]) > > b = np.array ([[5,6]]) > > c = np.concatenate ((a, b)) Axis=0) # axis=0 means stitching along the vertical direction of the array > print (c) [[1 2] [3 4] [56]] > d = np.concatenate ((a, b.T), axis=1) # axis=1 means splicing along the horizontal direction of the array > print (d) [[1 25] [3 46]]

Compare the run time of the numpy.append () and numpy.concatenate () functions

Example:

> from time import clock as now > a=np.arange (9999) > b=np.arange (9999) > > time1=now () > c=np.append (afort b) > time2=now () > print (time2-time1) 28.2316728446 > a=np.arange (9999) > b=np.arange (9999) > time1=now () > c=np.concatenate ((aMagneb), axis=0) > > time2=now () > print (time2-time1) 20.3934997107

It is known that concatenate () is more efficient and suitable for large-scale data splicing.

The above is all the contents of the article "how to use the numpy.concatenate () function". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

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