当前位置:网站首页>Numpy Foundation
Numpy Foundation
2022-07-29 05:13:00 【m0_ sixty-five million one hundred and eighty-seven thousand fo】
NumPy(Numerical Python) yes Python An extended library of language , Support a large number of dimension arrays and matrix operations , In addition, it also provides a large number of mathematical function libraries for array operation , Mainly used for array calculation .
NumPy install : stay cmd The input terminal pip install numpy. In the use of Numpy Before , adopt import The order will numpy Library import , And named it np, for example :import numpy as np.
Catalog
Arrays and scalars ( The set of real Numbers ) Operation between
Operations between arrays of the same dimension
Operations between arrays of different dimensions
Create an array from a list
One dimensional array
We can first define a list , And then through np.array() Function to convert data types and define a one-dimensional array .
data=[6,7.5,8,0,1] # Create a list of
arr=np.array(data) # Convert to a one-dimensional array Two dimensional array
First define a list of nested list elements , And then through np.array() Function to perform data type conversion and define a two-dimensional array .
data=[[1,2,3,4],[5,6,7,8]] # Create nested sequences
arr=np.array(data) # Convert to 2D array Create an array by function
utilize numpy The functions provided are convenient to create some specific arrays , The details are as follows :
function | meaning |
np.zeros() | Create specified dimension full 0 Multidimensional arrays . |
np.ones() | Create specified dimension full 1 Multidimensional arrays . |
np.eye() | Create the identity matrix of the specified dimension . |
np.arange() | Creates a specified number of sequential arrays ( Default 0 Start ). |
linspace() | Create a one-dimensional array with a specified range , And divided into several equal parts . |
reshape() | Change the dimension of the array |
Operation of array
Arrays and scalars ( The set of real Numbers ) Operation between
arr=np.array([[1,2,3],[4,5,6]]) # Create a 2D array
arr+2 | arr-2 | arr*2 | arr/2 |
array([[3,4,5], [6,7,8]]) | array([[-1,0,1], [2,3,4]]) | array([[2,4,6], [8,10,12]]) | array([[0.5,1.,1.5], [2.,2.5,3.]]) |
Operations between arrays of the same dimension
arr1=np.array([[1,2,3],[4,5,6]])
arr2=np.array([[2,2,2],[2,2,2]])
arr1+arr2 | arr1-arr2 | arr1*arr2 | arr1/arr2 |
array([[3,4,5], [6,7,8]]) | array([[-1,0,1], [2,3,4]]) | array([[2,4,6], [8,10,12]]) | array([[0.5,1.,1.5], [2.,2.5,3.]]) |
Operations between arrays of different dimensions
When calculating arrays of different dimensions , Arrays have broadcast properties , That is, automatically expand the dimension .

Index of array
contain n The index of the array of elements is 0,1,…,n-1.
Axis
stay numpy Can be understood as direction , Use 0,1,2... Digital representation , For a one-dimensional array , only one 0 Axis , about 2 Dimension group (shape(2,2)), Yes 0 Axis and 1 Axis , For three-dimensional arrays (shape(2,2, 3)), Yes 0,1,2 Axis .
One dimensional array index

Two dimensional array index

Boolean index

Ternary operator
Ternary operator np.where( expression , Count 1, Count 2), When the expression is true , The result is a number 1, Otherwise, the result is a number 2.
function
The generic function
A general function is a function of array A function that performs element-level operations on the data in . You can think of it as a vectorization wrapper for simple functions .
One variable function
function | explain |
Abs、fabs | Calculate the whole number 、 The absolute value of a floating-point number or negative number , For non complex values , You can use faster fabs |
sqrt | Calculate the square root of each element , amount to arr**0.5 |
Square | Calculate the square of each element . amount to arr **2 |
exp | Calculate the index of each element e* |
log、log10、log2、log1p | They are natural logarithm ( The base number is e)、 The base number is 10 Of log、 The base number is 2 Of log、log(1+x) |
sign | Calculate the sign of each element :1( Positive numbers )、o( zero )、 One 1( negative ) |
Cell | Calculate the ceiling value , That is, the smallest integer greater than or equal to the value |
floor | Calculate the floor value , That is, the maximum integer less than or equal to this value |
Dual function
function | explain |
add | Add the corresponding elements in the array |
subtract | Subtracts the elements of the second array from the first array |
multiply | Array element multiplication |
divide、floor_dvide | Division or downward rounding Division ( Discard the remainder ) |
power | For the elements in the first array A, According to the corresponding element in the second array B, meter . count AB |
maximum、 fmax | Calculation of the maximum value at the element level .fmax Will ignore NaN |
minimum、fmin | Calculation of minimum value at element level .fmin Will ignore NaN |
mod | Modular computation at the element level ( The remainder of division ) |
copysign | Assign the value in the second array to the value in the first array |
边栏推荐
- Deep learning brush a bunch of tricks of SOTA
- Reply from the Secretary of jindawei: the company is optimistic about the market prospect of NMN products and has launched a series of products
- Deadlock analysis using jstack, jconsole, and jvisualvm
- 传奇如何一台服务器配置多个版本微端更新
- How to open IE browser by running win command
- How does WPS take quick screenshots? WPS quick screenshot method
- Activity workflow table structure learning
- Lenovo Savior r7000+ add ssd+ copy and partition the information of the original D disk to the new SSD
- Google GTEST event mechanism
- How to add traffic statistics codes to the legendary Development Zone website
猜你喜欢

How to monitor micro web services

Quick start JDBC

How does word view document modification traces? How word views document modification traces

Mysql把查询到的结果集按指定顺寻进行排序

Self join and joint query of MySQL

Mapper agent development
![[untitled]](/img/6c/df2ebb3e39d1e47b8dd74cfdddbb06.gif)
[untitled]

Pytorch learning notes

Jackson parsing JSON detailed tutorial

Solution | get the relevant information about the current employees' highest salary in each department |
随机推荐
传奇如何一台服务器配置多个版本微端更新
How to add a map to the legendary server
How to set row height and column width in excel? The method of setting row height and column width in Excel
How to debug UDP port
About realizing page Jump of website in Servlet
[config] configure array parameters
SM整合原来这么简单,步骤清晰(详细)
Original code, inverse code, complement code
Pivot table of odoo development tutorial
js(forEach)出现return无法结束函数的解决方法
[untitled]
Word如何查看文档修改痕迹?Word查看文档修改痕迹的方法
How to install Office2010 installation package? How to install Office2010 installation package on computer
时间序列分析的表示学习时代来了?
What servers are needed to build mobile app
Create a mindscore environment in modelars, install mindvision, and conduct in-depth learning and training (Huawei)
Jackson parsing JSON detailed tutorial
[untitled]
About the configuration and use of thymeleaf
Mysql的自连接和联合查询