In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-09-22 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article mainly explains "what are the characteristics of python ndarray array objects". The content of the explanation is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn "what are the characteristics of python ndarray array objects".
1. The numpy array is a homogeneous array, that is, all elements must have the same data type.
2. The ndarray array generally requires that all elements have the same data type, with the subscript starting from 0, and the subscript of the last element is the array length minus 1.
Instance import numpy as np a = np.arange (0,5,1) print (a) b = np.arange (0,10,2) print (b)
Expansion of knowledge points:
Define array
> import numpy as np > m = np.array ([[1, 2, 3], [2, 3, 4]]) # define the matrix Int64 > marray ([[1dje 2je 3], [2pje 3je 4]]) > > m = np.array ([1je 2jue 3], [2p3e 4]], dtype=np.float) # definition matrix, float64 > marray ([[1,2.3,3], [2.3.4]]) > > print (m.dtype) # data type float64 > > print (m.shape) # shape 2 rows and 3 columns (2 columns) 3) > print (m.ndim) # Dimension 2 > print (m.size) # element number 6 > print (type (m))
There are also some special ways to define matrices
> m = np.zeros ((2Power2)) # all 0 > marray ([0.,0.], [0.,0]]) > print (type (m)) # is also a ndarray type > m = np.ones (2Power2) 3)) # all 1 > m = np.full ((3), 7) # all 7 > np.eye (3) # Unit matrix array ([[1,0.,0.], [0.1,1. 0.], [0, 0, 1.]) > np.arange (20) .reshape (4) 5) # generate an array of 4 rows and 5 columns > np.random.random (2) # [0) array ([[0.51123127, 0.40852721, 0.26159126], [0.42450279, 0.34763668, 0.06167501]) > np.random.randint (1) (1) array ([5) 2 rows and 3 columns of random integers 4, 9], [2, 5, 7]) > > np.random.randn (2, 5, 7]) # normal random distribution array ([[- 0.29538656,-0.50370707,-2.05627716], [- 1.50126655, 0.41884067, 0.67306605]]) > > np.random.choice ([10 ~ 20 ~ 20 ~ (30)], (2 ~ ~ 3)) # randomly select array ([10, 10], [30, 10, 20]) > > np.random.beta (1, 10) (2d3) # Beta Distribution array ([[0.01588963, 0.12635485, 0.22279098], [0.08950147, 0.02244569, 0.00953366]])
Operand array
> > from numpy import * > > a1=array # define an array > a2=array ([2pyr2]) > a1+a2 # for the addition of elements array ([3,3,3]) > a1min2 # multiplies a number array ([2pyr2]) # > a1=np.array ([1pyrr2]) > > a1array ([1mem2mem3]) > a1mem2 (3) means to do cube array ([1,8,8]) for each number in the array 27]) # # value Notice that it starts with 0. No matlab is different > > A1 [1] 2distinct # defines a multidimensional array > a3=np.array ([[1pime 2jing3], [4pje 5je 6]]) > a3array ([[1pl 2pies 3], [4pc5pr 6]]) > > A3 [0] # fetches the first row data array ([1mem2p3]) > A3 [0mem0] # the first data of the first row 1 > a3 [0] [0] # can also be used in this way ([1 [1] > > a3array) 2, 3], [4, 5, 6]) > > a3.sum (axis=0) # add by line Column invariant array ([5,7,9]) > a3.sum (axis=1) # add by column, row invariant array ([6,15]) Thank you for your reading, these are the contents of "what are the characteristics of python ndarray array objects". After the study of this article, I believe you have a more profound understanding of the characteristics of python ndarray array objects, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!
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.