In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-15 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
How to analyze the python numpy library, many novices are not very clear about this, in order to help you solve this problem, the following editor will explain for you in detail, people with this need can come to learn, I hope you can gain something.
1.NumPy (Numeric Python)
Numpy is an open source python scientific computing extension library, which is mainly used to deal with arbitrary dimensional arrays and matrices.
For the same task, using numpy is simpler and more efficient than using the basic data structure of python directly.
Its functions are:
Contains a powerful N-dimensional array object Ndarray
Broadcast function
A tool to integrate the code of CumberCraft +
Linear algebra, Fourier transform, random number generation and other functions
Numpy is the basis of data processing or scientific computing libraries such as scipy,pandas.
Reference to 2.numpy
Although aliases can be omitted or changed, try to use aliases of the above convention.
3.Ndarray
An n-dimensional array, which is a collection of the same data type, starting with 0 as the subscript to index the elements in the collection.
We know that python has data structures such as lists and arrays.
List: data types can be different (e.g. [3,2.4,'a', "abc"]), and the data is ordered
Array: the data type is the same (for example, [1pm, 2pm, 3p4])
Collection: (for example, {2pc4rec 3pr 5p7}) the data is out of order.
The meaning of introducing n-dimensional array
Observe the following two sets of operations, the function is the same.
Import numpy as npdef pysum (): a = [1,2,3,4] b = [5,6,7,8] c = [] for i in range (len (a)): c.append (a [I] * * 2roomb [I] * * 3) return cdef numpysum (): a = np.array ([1,2,3,4]) b = np.array ([5,6,7) 8]) c = a**2+b**3 return cprint ("the result of using list operation is:", pysum ()) print ("the result of using Numpy operation is:", numpysum ())
Running result:
The result of using the list operation is: [126,220352,528]
The result of using Numpy operation is: [126 220 352 528]
But it's clear:
The array objects of numpy can remove the loops needed by elements to build operations, making one-dimensional vectors more like a single data.
Numpy sets up special array objects, and after optimization, the operation speed is also improved accordingly.
In general, in scientific operations, all data types in a dimension are often the same. At this time, using array objects to use the same data type helps to save computing time and storage space.
The composition of ndarray
Actual data
Metadata that describes this data (data dimensions, data types, etc.)
Properties of the ndarray object
3. Data type
When np.array () does not specify dtype, numpy will associate a dtype type according to the data situation
Reasons why ndarray supports multiple data types
Python basic syntax only supports three types: integer, floating point and plural.
Scientific computing involves a lot of data and has high requirements for storage and performance.
Fine definition of element types helps numpy to make rational use of storage space and optimize performance
The fine definition of element types is helpful for programmers to make a reasonable evaluation of the program size.
The creation of ndarray array
Import numpy as npx = np.array ([[1,0], [2,0], [3,1]], np.int32) print (x) print (x.dtype)
Program output:
[[1 0]
[2 0]
[3 1]]
Int32
Transformation of adarray array
Ndarray array operation
4. Index and slicing
Index: the process of getting elements at a specific location in an array
Slicing: the process of getting a subset of array elements
5. Random number function
6. Statistical function
7. Gradient function
8. Copy and view
Numpy linear algebra
Operation between array and scalar
Summary of commonly used numpy.linalg functions
Is it helpful for you to read the above content? If you want to know more about the relevant knowledge or read more related articles, please follow the industry information channel, thank you for your support.
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.