In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
This article introduces the relevant knowledge of "what is the role of numpy in python". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!
To be continue NumPy (Numerical Python) is an extension library of Python language, which not only supports a large number of dimensional array and matrix operations, but also provides a large number of mathematical function libraries for array operations.
Import file
Import numpy as np
Ndarray: a Multi-dimensional Array object
Create array create array from the python list all data types are the same. If a list with different types of elements is passed in, array attempts to convert automatically
Datal = np.array ([1, 3, 4, 2])
You can also pass in a multidimensional list
Datal2 = np.array ([[1, 2, 3, 4], [3, 4, 5, 6]))
This method is faster than the python list to create an array. The function creates a value of 0 for np.zeros ((3je 5), dtype=float) creates an empty array with a value of 1, and a data type of float np.empty ((2m 3c 2)). When you create an empty array, you just take out the corresponding memory size There may be other data np.full ((3prime4), 3.14) in it because of memory residue. Create an array np.arange (0prim20) with initialization of 3.14 from 0 to 20 with a step size of 2 np.linspace (0pencil 5) evenly generate 5 numbers from 0 to 1 (i.e., 0min0.25, 0.5, 0.75, num) np.eye (num) create a unit matrix np.random.random (3), create a 33 Create a random array of 33 with a mean of 0 and a variance of 1 with a normal distribution of random array np.random.normal (0 True or False 1, (3p3)) between 0 and 1. The 33 random integer array np.random.seed () random number seed numpy data type Data type Description bool_ Boolean (True or False) stored as a byte int_ Default integer type (same as C long) between 0 and 1. Normally either int64 or int32) intc Identical to C int (normally int32 or int64) intp Integer used for indexing (same as C ssize_t; normally either int32 or int64) int8 Byte (- 32768 to 32767) int32 Integer (- 2147483648 to 2147483647) int64 Integer (- 9223372036854775808 to 9223372036854775807) uint8 Unsigned integer (0to) uint16 Unsigned integer (0to 65535) uint32 Unsigned integer (0 to 4294967295) uint64 Unsigned integer (0 to 1844674407709551615) float_ Shorthand for float64. Float16 Half precision float: sign bit, 5 bits exponent, 10 bits mantissa float32 Single precision float: sign bit, 8 bits exponent, 23 bits mantissa float64 Double precision float: sign bit, 11 bits exponent, 52 bits mantissa complex_ Shorthand for complex128. Complex64 Complex number, represented by two 32-bit floats complex128 Complex number, represented by two 64-bit floats character correspondence type b Boolean I (signed) integer u unsigned integer integer f floating point c complex floating point m timedelta (interval) M datetime (date time) O (Python) object S, a (byte-) string U Unicode V raw data (void) data type conversion astype ('data type') does not modify the original array Only a copy of the array will be returned. If a floating point number is converted to an integer, it will truncate the decimal part of the string. It can only be converted to a floating point number first, not directly to an integer.
Array attributes and method attributes ndim Array Dimension shape returns a tuple of each dimension size the total number of size elements dtype returns the data type of the array itemsize each element occupies memory size nbytes the entire array occupies memory
The method copy ()-- creates a copy of the array reshape ()-- re-adjusts the number of rows, columns, and dimensions of the matrix to return a new array. Share memory with the original array
Np.newaxis-add one dimension to the current location, for example: X1 [np.newaxis,:] means to add a line
Np.concatenate ()-can concatenate two or more arrays at a time
(A1, A2, …) : array axis=0 to be stitched: along which dimension to concatenate. The default is 0, and it is split horizontally. When 1, the np.vstack ()-vertical stack is split vertically, np.hstack ()-horizontal stack is spliced in the first dimension (row), and spliced in the second dimension (column).
Np.split ()-- splits an array sequentially from left to right
Ary: array to be split indices_or_sections: if it is an integer, use this number to split averagely. If it is an array, it is the position along the axis (left open and right closed) axis=0: along which dimension to carry out tangential direction, default is 0, horizontal split. When 1, longitudinal segmentation np.vsplit ()-vertical segmentation np.hsplit ()-horizontal segmentation
Indexes and slices can be indexed using the methods commonly used by python. In addition, you can also use comma-separated index tuples to obtain the element num [0J0] = = num [0] [0].
Boolean indexes support common logical operators. The original array can be used to select the compared results, and the return value is the number of True. It can be operated, and True is 1, and false is the 0 logical operator, numpy function.
Np.greater < np.less = = np.equal! = np.notequal
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.