In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-09-15 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article mainly explains "the meaning of colons and minus signs in numpy array". Interested friends may wish to take a look at it. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn the meaning of colons and minus signs in the numpy array.
When actually using numpy, we often use the-1 dimension and ":" of the numpy array to call elements in the numpy array. I am also often confused by the dimensions of the array.
In general, ":" is used to represent all submodules of the current dimension
"- 1" is used to indicate the last of all sub-modules in the current dimension, and "negative sign is used to indicate elements counted from back to front."
Test code
Import numpy as npb = np.arange (start=0, stop=24, dtype=int) print ('b.shapestones, b.shape) # b.shape (24,) b1 = b.reshape ((4,2,3) print (' the value of b1\ n') B1) # the value of bundles [0 12] # [3 45]] # # [[6 7 8] # [9 10 11]] # [[12 13 14] # [15 16 17]] # [[18 19 20] # [21 22 23] print ('b1 [- 1]\ n' B1 [- 1]) # decompose the last module from the outermost dimension # b1 [- 1] # [[18 19 20] # [21 22 23]] for an in b1 [- 1]: print ('s') # there are two small modules in this module So the program runs # s # sprint ('b1 [:-1]\ n 'twice B1 [:-1]) # the remaining module # b1 [:-1] # [0 12] # [3 45]] # [[6 7 8] # [9 10 11]] # [[12 13 14] # [15 16 17] for A1 in b1 [:-1]: print ('s') # has three small modules in this module So the program runs twice # s # s # sprint ('b1 [- 1:]\ nkeeper, b1 [- 1:]) # is written in the ":" of the last dimension has no substantive effect The meaning expressed here is the same as b1 [- 1] # b1 [- 1:] # [18 19 20] # [21 22 23] print ('b1 [:,-1]\ ndimension, b1 [:,-1]) # indicates that the last submodule # b1 [is selected in each submodule after all the outermost dimensions are taken out: -1] # [[3 45] # [9 10 11] # [15 16 17] # [21 22 23]] print ('b1 [:,-1]\ nB1 [:,:,-1]) # indicates that the last element of the innermost dimension is taken to form a new tuple # b1 [:,-1] # [[25] # [8 11] # [14 17] # [20 23] I believe you have a deeper understanding of "the meaning of colons and minus signs in the numpy array". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!
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.
The market share of Chrome browser on the desktop has exceeded 70%, and users are complaining about
The world's first 2nm mobile chip: Samsung Exynos 2600 is ready for mass production.According to a r
A US federal judge has ruled that Google can keep its Chrome browser, but it will be prohibited from
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
About us Contact us Product review car news thenatureplanet
More Form oMedia: AutoTimes. Bestcoffee. SL News. Jarebook. Coffee Hunters. Sundaily. Modezone. NNB. Coffee. Game News. FrontStreet. GGAMEN
© 2024 shulou.com SLNews company. All rights reserved.