In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.