Current location - Plastic Surgery and Aesthetics Network - Plastic surgery and beauty - What are the common functions in numpy based on Python?
What are the common functions in numpy based on Python?
Some Python Whites don't know much about the commonly used functions in numpy. Today, Bian Xiao will sort them out and share them with you.

Numpy is a scientific computing library in Python, which provides the function of matrix operation. It is usually used with Scipy and matplotlib. In fact, list has provided a matrix-like representation, but numpy provides us with more functions.

Array common function

1.where () conditionally returns the index value of an array.

2.take(a, index) gets the value from the array A according to the index index.

3.linspace(a, b, n) returns an array evenly distributed in the range of (a, b), with n elements.

4.a.fill () fills all the elements of the array with the specified values.

5.diff(a) returns an array consisting of the differences between adjacent elements of array A.

6.sign(a) returns the symbol of each element in array a.

7. The segmented (a, [condlist], [funclist]) array A returns the corresponding element results according to the Boolean condlist condition.

8.a.argmax (), a.argmin () returns the indexes of the largest and smallest elements of a.

Change array dimensions

A.ravel (), A.Flat (): flatten the array a into a one-dimensional array.

A.shape=(m, n), a. shape(m, n): converts the array A into an array of m*n dimensions.

Transpose array a

Array combination

1.h stack ((a, b)), concatenate ((a, b), axis = 1) combine arrays A and B in the horizontal direction.

2.vstack ((a, b)) and concatenate ((a, b), axis = 0) combine arrays A and B in the vertical direction.

3.row_stack((a, b)) combines arrays A and B in the row direction.

4.column_stack((a, b)) combines arrays A and B in the column direction.

Array segmentation

1.Split (a, n, axis = 0) and vsplit (a, n) vertically divide array a into n arrays.

2.Split (a, n, axis = 1), split (a, n) horizontally divides the array A into n arrays.

Array pruning and compression

1.a.clip(m, n) sets the range of array A to (m, n), sets the elements greater than n in the array to n, and sets the elements less than m to m..

2.a.compress () returns an array filtered according to a given condition.

Array attribute

The data type of 1. a. d type array a.

2.a. Shape dimension of shape array A

3.3.the dimension of a.ndim array a

4.4.a.size total number of elements contained in array a.

5.a. Number of bytes occupied by elements of itemsize array A in memory.

6.a.nbytes Memory space occupied by the whole array A 7.a.astype(int) converts the type of array A into int type.

Array calculation

1.average(a, weights=v) averages the array a with the weight v.

2.mean (a), max (a), min (a), middle (a), var (a), STD (a) the average, maximum, minimum, median, variance and standard deviation of array a.

3.a.prod () product of all elements of array a.

Cumulative product of array a elements.

Cov (a, b), corr coef (a, b) covariance and correlation coefficient of arrays a and b.

6.a.diagonal () Look at the diagonal elements of matrix A 7.a.trace () Calculate the trace of matrix A, that is, the sum of diagonal elements.

These are commonly used functions in numpy. More PyThon learning recommendations: Python learning network teaching center.