First, elementwise operations
1, with scalars:
Input:
Import NumPy as np
a = Np.array ([1, 2, 3, 4])
A + 1
Output:
Array ([2, 3, 4, 5])
Input:
2**a
Output:
Array ([2, 4, 8, 16])
2. All arithmetic operates elementwise: input:
b = Np.ones (4) + A number creates an array with a value of 1 and then subtracts 1 (each element Plus)
b
a-b# the corresponding element
Output:
Array ([ -1., 0., 1., 2.])
Input:
A * b
Output:
Array ([2., 4., 6., 8.])
Input:
j = Np.arange (5)
2** (j + 1)-J
Output:
Array ([2, 3, 6, 13, 28])
3. Matrix multiplication:
Input:
c = NP. ((3,3))
C.dot (c) #矩阵乘法
Output:
Array ([[3., 3., 3.],
[3., 3., 3.],
[3., 3., 3.]]
4. Comparison and bitwise operation of matrices:
5, Transcendental function:
6, the shape does not match the operation
7, upper triangular matrix, transpose
Np.triu is the upper triangular matrix and the np.tril is the lower triangular matrix.
8, matrix comparison:
Second, the Sub module Numpy.linalg realize the basic linear algebra (Linear algebra), such as solving linear systems, singular value decomposition, and so on. However, it is not guaranteed to compile with valid routines, so we recommend using SCIPY.LINALG, detailed in the Scipy_linalg section
1, and Operations (total sum, by row/column sum)
2, mean value (mean), median (median), standard deviation (STD)
3, to find the maximum, minimum, maximum index, minimum index
4, the logical operation in the array
5, the overall comparison of the array
Np.zeros ((100,100))--a matrix that produces a 100*100 with a value of all 0
Np.all () all numbers are compared