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

What is the use of the numpy.insert () function

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

Share

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

This article is about what numpy.insert() function is used for. Xiaobian thinks it is quite practical, so share it with everyone for reference. Let's follow Xiaobian and have a look.

Numpy function

insert function

numpy.insert can have three parameters (arr, obj, values) or four parameters (arr, obj, values, axis):

The first argument arr is an array, which can be one-dimensional or multidimensional, and inserts elements on top of arr

The second parameter obj is where the element is inserted

The third parameter values is the value to insert

The fourth parameter axis indicates which axis to insert at the corresponding insertion position

If the fourth argument is not given, then the default is to flatten arr into a one-dimensional array, and then insert the corresponding value in the corresponding position.

The following are examples:

arr2=np.array ([1,2,3,4,5])arr3=arr2.reshape(-1,1)arr=np.insert (arr3,1,[[0],[0]],axis=0)#arr=np.insert (arr3,slice(1,2),[[0],[0]],axis=0) where slice means slice, as in numpy print (arr3)print(arr3)arr.flatten()[[1][2][3][4][5][1][0][2][3][4][5] array ([1, 0, 0, 2, 3, 4, 5])arr=np.insert (arr,4,[[0],[0]],axis=0)#where 4 indicates the position obj, insert valuearr=np.insert after several positions (arr,7,[[0],[0]],axis=0)arr=np.insert(arr,10,[[0],axis=0)print(arr.flatten())[1 0 2 0 0 3 0 0 4 0 5] Thank you for reading! About "numpy.insert() function what to use" This article is shared here, I hope the above content can be of some help to everyone, so that everyone can learn more knowledge, if you think the article is good, you can share it to let more people see it!

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