numpy
func
Basics of Interface Methods
reduce, aggregation method
accumulate, cumulative aggregation
reduceat, aggregate by specified axis and specified slice
outer: outer product
ndarray
Basics of Data Structures
specific function structure
Create a random series from a specific library function
Create an array of specific structures
arange: similar to the range function, but can specify any start, end and step size, not limited to integers
linspace: the current uniform distribution, similar to arange, but the third parameter is the number
logspace: logarithmic uniform distribution
ones, ones_like all 1 array
zeros, zeros_like all 0 array
empty,empty_like empty array
full, full_like formulate a numerical array, equivalent to val ones()
identity: generate identity matrix
eye: the diagonal is 1, you can set up or down
diag: accepts an array and returns the elements on its diagonal
Branch topic 11
Ordinary structures create arrays
array, create an array from a known structure
append, append one or more slices after a certain dimension
insert: insert one or more
delete: delete one or more slices of a dimension
reshape returns the new array after the array has been reshaped, and the number of elements must be the same
It can also be deformed by specifying the shape, which is equivalent to the inplace operation
x.resize performs inplace operation on the array x, and the size is truncated or filled with 0 according to the situation
np.resize(x) returns a new array after reshaping, the original array x remains unchanged, and fills with the original array when there are insufficient elements
Return the heterotopic representation of the array: revel() method, flat attribute
Returns the transposed form of the array, transpose() method, T attribute
np.title(*, reps): copy the array, repeat by array
np.repeat(): Copy the array and repeat by element
concatenate: Concatenate multiple arrays along a certain axis. It is required that the concatenation axis must exist (that is, the dimension cannot be increased). The default is 0, that is, row concatenation. When axis=None, first flatten the vector and then perform concatenation. The concatenation of vectors is row splicing
hstack: Stack multiple arrays horizontally, that is, stack according to axis=1, and require the same dimensions except for this column. If it is a heterogeneous array (vector), stack according to axis=0, and the result is still one-dimensional.
column_stack: Similar to hstack, except that when stacking two one-dimensional arrays, they are stacked by column vectors
vstack: For multiple arrays to be stacked vertically, that is, to stack according to axis=0, the other dimensions outside this column are required to be the same. If it is a one-dimensional array (vector), it will be automatically reshaped into 1xN and then stacked. At least 2 dimensions after stacking
row_stack: Consistent with vatack, when processing one-dimensional arrays, it will first be upgraded to two-dimensional processing
dsack: Perform row-depth stacking for multiple arrays, that is, stacking according to axis=2, except for this column, other dimensions are required to be the same
stack: Perform dimension-up stacking, accept an axis parameter to insert a new dimension, the default is 0,. Different from hstack and vstack
r_[]: stack by row, magic method (not function), the effect is similar to vstack
c_[ ]: stack by column, magic method (not a function), the effect is similar to hstack
hsplit: Horizontal splitting, which requires the size to be equal after splitting, the dimension remains unchanged, and one-dimensional arrays can be split
vsplit: Vertical splitting, requiring equal size after splitting, constant dimensionality, requiring at least two dimensions
dsplit: Depth splitting, requiring equal size after splitting, constant dimension, at least three-dimensional array
split: Arbitrary splitting is achieved by receiving an axis parameter, the default axis=0, if axis=1 or 2 is set, vstack and dstack can be realized respectively
array_split: The first four methods all require the splitting of sub-arrays of the same size, and an error will be reported when the number of splits cannot be divisible. array_split is suitable for splitting under approximately equal conditions, and also accepts an axis parameter to achieve the specified axis
max, argmax return the maximum value and the corresponding index of the maximum value respectively, and can receive an axis parameter to specify the aggregation statistics of the axis. For two-dimensional and above arrays, if axis is not specified, that is, axis=None, aggregate statistics will be calculated for all values of the array
min, argmin, agree with max
mean, std, calculate the mean and standard deviation respectively, and can also receive a default parameter axis to achieve specific axial aggregation statistics or global aggregation
var, cov, find the variance and covariance respectively, similar to the mean standard deviation
sort, argsort, respectively return the sorted array and the corresponding index, receive an axis parameter, the default is axis=-1, according to the last axis, if axis=None means flatten into a one-dimensional array before sorting; in addition, it can be set Sorting algorithms, such as quick sort, heap sort, or merge
Direct assignment: no backing, simple reference (id(a)==id(b))
view: create a view, shallow copy, data common
Data slicing is essentially building a view
copy: realize deep copy, completely independent
inf/Inf/Infinity/PINF: positive infinity
NINF: negative infinity
NAN/NaN/nan: non-numeric
pi:π
e: natural constant
np.newaxis: an alias of None, generally used to increase the dimension of the array
random: returns a specified number of uniformly distributed random numbers between 0 and 1
rand: accepts parameters as the dimension and returns a uniformly distributed random number between 0 and 1
uniform: Accept upper and lower bound parameters, and return a uniform random number of specified size
randn: returns a random number from the standard normal distribution (mean 0, variance 1)
normal: Accept the expectation and variance, and return a random number with a normal distribution of a specified size (the loc mean and scale variance can be set)
permutation: returns the random permutation result of the sequence
Shuffle: inplace random arrangement of the array (shuffle the order, rearrange)
choice: Randomly select an element from the input sequence
seed: Generate random number seed, random result after solidification
dot: globally available, matrix dot product
vdot: Dot product is performed in one dimension regardless of the input dimension
linalg.qr: QR boundary
linalg.svd: SVD boundary
linalg.eig: solve for eigenvalues and eigenvectors
linalg.norm: solve the norm
linalg.det: solve determinant
linalg.solve: Solve the equation of Ax=b
linalg.inv: Find the inverse of a matrix
understand
Understand numpy's axis
broadcast mechanism ufunc
Summary of numpy knowledge points
Guess you like
Origin blog.csdn.net/chehec2010/article/details/131088828
Recommended
Ranking