python--ufunc function--numpy calculation

NumPy "Universal Function" (ufunc)
·Element-level functions: perform operations on each element in the
array·Array-level functions: statistical functions, functions like aggregates, summation, average, etc.


Calculate the absolute value abs

import numpy as np
arr = np.array([5,2,0,-1,-3,-1,-4])
np.abs(arr)
#array([5, 2, 0, 1, 3, 1, 4])

Calculate the square of each element

np.square(arr)
#array([25,  4,  0,  1,  9,  1, 16], dtype=int32)

Square root of each element

np.sqrt(arr)

Exponent based on e (E to the power of X)

np.exp(arr)

Logarithm to base e

np.log(arr)
np.log10(arr)
np.log2(arr)

Returns the sign of each element

np.sign(arr)

Sort (default ascending) sort

np.sort(arr)

#多维数组排序
arr.sort(axis=1)

Remove duplicate elements

arr=np.array([5.2,-0.1,3,14])
np.unique(arr)

Improvement / trade-in

np.ceil(arr)
np.floor(arr)

rounding

np.rint(arr)

Decimal integer separation

np.modf(arr)

Trigonometric function

np.tan(arr)
np.cos(arr)
np.sin(arr)

Sum

np.sum(arr)

Average

np.mean(arr)

Standard deviation

np.std(arr)

variance

np.var(arr)

Min/max value and index

np.min(arr)
np.max(arr)
np.argmaxin(arr)
np.argmax(arr)

Cumulative sum/product of array elements

np.cumsum(arr)
np.cumprod(arr)

Matrix operations numpy.linalg

Returns the diagonal elements of the matrix

np.diag(a)

Diagonal elements and

np.trace(a)

Calculate the matrix determinant
Insert picture description here

np.linalg.det(a)

Matrix inverse

np.linalg.inv(a)

Matrix dot
Insert picture description here
product np.dot (a, aT)

Guess you like

Origin blog.csdn.net/weixin_44039266/article/details/114752032