Reference link: numpy.flip in Python
Reference link: numpy.geomspace in Python
table of Contents
Array creation routine
for example:
From existing data
Create record array (numpy.rec)
Create character array (numpy.char)
Value range
Build the matrix
Matrix class
Array operation routine
Basic operation
Change the shape of the array
Transpose-like operations
Change dimension
Change the type of array
Concatenate array
Split array
Tiled array
Add and delete elements
Rearrange elements
String manipulation
String manipulation
Compare
String information
Convenience
Date and time support function
Business day function
Array creation routine
empty(shape[, dtype, order]) returns a new array of the given shape and type without initializing the entries. empty_like (prototype [, dtype, order, subok]) returns a new array with the same shape and type as the given array. eye(N [, M, k, dtype, order]) returns a two-dimensional array, where the diagonal is 1, and the zero point is zero. identity(n[,dtype]) returns an array of identity. ones(shape[, dtype, order]) returns a new array of the given shape and type, filled with one. ones_like(a[, dtype, order, subok]) returns an array with the same shape and type as the given array. zeros(shape[,dtype,order]) returns a new array of the given shape and type, filled with zeros. zeros_like(a[, dtype, order, subok]) returns an array of zeros with the same shape and type as the given array. full(shape, fill_value [, dtype, order]) returns a new array of the given shape and type, filled with fill_value. full_like(a, fill_value[, dtype, order, subok]) returns a complete array with the same shape and type as the given array.
for example:
numpy.empty(shape, dtype=floating point number, order='C')
Return a new array of the given shape and type without initializing the entries.
Parameters: shape: the shape of an empty array of tuples of int or int, for example, or. (2, 3)2 dtype: Data type, optional expected array output data type, such as numpy.int8. The default is numpy.float64. Order: {'C','F'}, optional, default:'C' Whether to store multidimensional data in the memory in the order of row major (C style) or column major (Fortran style). Returns: Out: ndarray An array of uninitialized (arbitrary) data of the given shape, dtype and order. The object array will be initialized to None.
>> np.empty([2, 2])
array([[ -9.74499359e+001, 6.69583040e-309],
[ 2.13182611e-314, 3.06959433e-309]]) #random
>>> np.empty([2, 2], dtype=int)
array([[-1073741821, -1067949133],
[ 496041986, 19249760]]) #random
From existing data
array (object [, dtype, copy, order, subok, ndmin]) creates an array. asarray(a[, dtype, order]) converts the input to an array. asanyarray(a[,dtype,order]) converts the input to an ndarray, but through the ndarray subclass. ascontiguousarray(a[,dtype]) returns a contiguous array (C order) in memory. asmatrix(data[,dtype]) interprets the input as a matrix. copy(a[, order]) returns an array copy of the given object. frombuffer(buffer[,dtype,count,offset]) interprets the buffer as a one-dimensional array. fromfile (file [, dtype, count, sep]) constructs an array based on the data in the text or binary file. fromfunction(function, shape, **kwargs) constructs an array by executing a function on each coordinate. fromiter(iterable, dtype[, count]) creates a new 1-dimensional array from an iterable object. fromstring (string [, dtype, count, sep]) A new 1-D array initialized from the text data in the string. loadtxt(fname [, dtype, comments, delimiter,...]) loads data from a text file.
Create record array (numpy.rec)
note
numpy.rec is the preferred alias numpy.core.records.
core.records.array (obj [, dtype, shape,...]) constructs a record array from a variety of objects. core.records.fromarrays(arrayList[,dtype,...]) creates an array of records from a (flat) array list core.records.fromrecords(recList[,dtype,...]) creates an array of records from a list of records in text form A rearranged core.records.fromstring(datastring[,dtype,...]) creates a (read-only) record array core.records.fromfile(fd[,dtype,shape,...] from the binary data contained in the string. .]) Create an array from binary file data
Create character array (numpy.char)
note
numpy.char is the preferred alias numpy.core.defchararray.
core.defchararray.array(obj[, itemsize,...]) creates a chararray. core.defchararray.asarray(obj[,itemsize,...]) converts the input to a chararray, copying the data only when necessary.
Value range
arange([start,] stop [, step,] [, dtype]) returns evenly spaced values within a given interval. linspace (start, stop [, num, endpoint, ...]) returns evenly spaced numbers within the specified interval. logspace(start, stop[,num,endpoint,base,...]) returns evenly spaced numbers on a logarithmic scale. geomspace (start, stop [, num, endpoint, dtype]) returns evenly spaced numbers (geometric series) on a logarithmic scale. meshgrid(*xi, **kwargs) returns the coordinate matrix from the coordinate vector. mgridnd_grid instance, it returns a dense multi-dimensional "meshgrid". ogridnd_grid instance, it returns an open multidimensional "meshgrid".
Build the matrix
diag(v[,k]) Extract diagonal lines or construct diagonal arrays. diagflat(v[,k]) uses the flattened input to create a two-dimensional array as a diagonal. tri (N [, M, k, dtype]) An array containing the given diagonal and numbers below the given diagonal, and the lower triangle of the zero tril (m [, k]) array elsewhere. triu(m[,k]) The upper triangle of the array. vander(x [, N, increase]) generates a Vandermonde matrix.
Matrix class
mat(data[,dtype]) interprets the input as a matrix. bmat(obj[,ldict,gdict]) constructs a matrix object from a string, nested sequence or array.
Array operation routine
Basic operation
copyto(dst, src[, cast, where]) copies values from one array to another, and broadcasts as needed.
Change the shape of the array
reshape(a, newshape[, order]) provides a new shape for the array without changing its data. ravel(a[,order]) returns a continuous flat array. A one-dimensional iterator on the ndarray.flat array. ndarray.flatten([Order]) returns a copy of the folded array to one dimension.
Transpose-like operations
moveaxis(a, source, destination) moves the axis of the array to a new position. rollaxis(a, axis[, start]) rolls the specified axis backward until it is at the given position. swapaxes(a, axis1, axis2) swaps the two axes of the array. ndarray.T is the same as self.transpose(), except that self is returned if self.ndim <2. transpose(a[, axis]) permutes the dimensions of the array.
Change dimension
atleast_1d (*arys) converts the input into an array with at least one dimension. atleast_2d (*arys) treats the input as an array with at least two dimensions. atleast_3d (*arys) treats the input as an array with at least three dimensions. broadcast makes an object that imitates broadcast. broadcast_to(array, shape[, subok]) broadcasts the array to a new shape. broadcast_arrays (*args, **kwargs) broadcast any number of arrays to each other. expand_dims (a, axis) expand the shape of the array. squeeze(a[,axis]) removes one-dimensional entries from the shape of the array.
Change the type of array
asarray(a[, dtype, order]) converts the input to an array. asanyarray(a[,dtype,order]) converts the input to an ndarray, but through the ndarray subclass. asmatrix(data[,dtype]) interprets the input as a matrix. asfarray(a[,dtype]) returns an array converted to float type. asfortranarray(a[,dtype]) returns an array laid out in Fortran order in memory. ascontiguousarray(a[,dtype]) returns a contiguous array (C order) in memory. asarray_chkfinite(a[, dtype, order]) Convert the input to an array, check NaN or Infs. asscalar (one) converts an array of size 1 to a scalar equivalent array. require(a[,dtype,require]) returns an ndarray of the provided type that meets the requirements.
Concatenate array
concatenate((a1, a2,...)[, axis, out]) joins a series of arrays along the existing axis. stack(array[, axis, out]) adds a series of arrays along the new axis. column_stack (TUP) stacks 1-D arrays as columns into 2-D arrays. dstack (TUP) stacks arrays in order (along the third axis) deeply. hstack (TUP) stacks arrays in order (column). vstack (TUP) stacks the array vertically (row mode). block (array) assembles an nd array from a list of nested blocks.
Split array
split(ary, indicators_or_sections[, axis]) splits the array into multiple sub-arrays. array_split(ary, indicators_or_sections[, axis]) Split the array into multiple sub-arrays. dsplit (ary, indicators_or_sections) splits the array into multiple sub-arrays along the 3rd axis (depth). hsplit(ary, indicators_or_sections) splits the array horizontally into multiple sub-arrays (by column). vsplit(ary, indicators_or_sections) splits the array vertically into multiple sub-arrays (row by row).
Tiled array
tile(A, representative) constructs an array by repeating the number of times A is given. repeat(a, repeat[, axis]) repeat the elements of the array.
Add and delete elements
delete(arr, obj[, axis]) returns a new array whose sub-axis array is deleted along the axis. insert(arr, obj, values[, axis]) insert values along the given axis before the given index. append(arr, value[, axis]) appends the value to the end of the array. resize(a, new_shape) returns a new array with the specified shape. trim_zeros(filt[, trim]) Trim leading and/or trailing zeros from a 1-D array or sequence. unique(ar[, return_index, return_inverse,...]) Find the unique element of the array.
Rearrange elements
flip(m[, axis]) Reverse the order of the elements in the array along the given axis. fliplr(M) Flip the array to the left/right. flipud (M) Flip the array up/down. reshape(a, newshape[, order]) provides a new shape for the array without changing its data. roll(a, shift[, axis]) rolls the array elements along the given axis. rot90(m[,k,axes]) rotates the array 90 degrees in the plane specified by the axis.
String manipulation
This module provides a set of vectorized string operations numpy.unicode_ for type numpy.string_ or arrays of type numpy.unicode_. All of these are based on the string methods in the Python standard library.
String manipulation
add(x1, x2) returns the element-wise string concatenation of two str or unicode arrays. multiply (a, i) returns (a * i), that is, multiple concatenations of strings, element by element. mod(a, value) returns (a%i), which is a pair of array_likes in which the element format is str or unicode before the 2.6 string formatting (iterpolation) of Python. capitalize(a) returns a copy of the first character of each element with only capital. center(a, width[, fillchar]) returns a copy of one with the element width in the center of the length string. decode(a[,code,error]) calls str.decode element-wise. encode(a[,code,error]) call str in element-wise. encode. join(sep, seq) returns a string, which is the concatenation of strings in the sequence seq. ljust(a, width[, fillchar]) returns a left-aligned string width with the element array. lower (one) returns an array whose elements are converted to lowercase. lstrip(a[,chars]) is one for each element, and returns a copy after removing the protagonist. partition (a, sep) divides each element into a surrounding sep. replace (a, old, new [, count]) One for each element, and all the old ones appearing in the copy of the string are replaced with new ones. rjust(a, width[, fillchar]) returns the width of a string with a right-aligned length to the array of elements. rpartition(a, sep) partitions (splits) each element around the rightmost separator. rsplit (a [, sep, maxsplit]) is one for each element, and the month is used as the separator string in the returned word list string. rstrip(a[,chars]) has one in each element, and returns a copy with the tail characters removed. split(a[,sep,maxsplit]) One for each element, the month is used as the separator string in the returned word list string. splitlines(a[,keepends]) one in each element, returns the elements in the list of lines, at the boundary of the break line. strip(a[,chars]) one in each element, which removes the leading edge and trailing characters and returns a copy. swapcase(a) returns a string copy of the element, with uppercase characters converted to lowercase, and vice versa. title (a) returns the string or unicode version of the element string. translate(a,table[,deletechars]) For each element one, return a string copy of all the characters that appear in the optional parameter. The deletechars are deleted, and the remaining characters have been mapped through the given conversion table. upper (one) returns an array whose elements are converted to uppercase. zfill(a, width) returns a numeric string filled with zeros on the left [,Deletechars]) For each element, return a copy of the string of all characters that appear in the optional parameter. The deletechars are deleted, and the remaining characters have been mapped through the given conversion table. upper (one) returns an array whose elements are converted to uppercase. zfill(a, width) returns a numeric string filled with zeros on the left [,Deletechars]) For each element, return a copy of the string of all characters that appear in the optional parameter. The deletechars are deleted, and the remaining characters have been mapped through the given conversion table. upper (one) returns an array whose elements are converted to uppercase. zfill(a, width) returns a numeric string filled with zeros on the left
Compare
Unlike the standard numpy comparison operators, those operators in the char module strip trailing blank characters before performing the comparison.
equal(x1, x2) is returned element-wise (x1 == x2). not_equal(x1, x2) is returned element-wise (x1!= x2). greater_equal(x1, x2) is returned element-wise (x1>= x2). less_equal(x1, x2) returns element-wise (x1 <= x2). greater (x1, x2) is returned element-wise (x1> x2). less (x1, x2) returns element-wise (x1 <x2).
String information
count(a, sub [, start, end]) returns an array containing the number of non-overlapping occurrences of substring sub in the range of [start, end]. find(a, sub[, start, end]) For each element, returns the lowest index in the string where substring sub is found. index (a, sub[, start, end]) such as find, but ValueError is raised when the substring is not found. isalpha (a) If all characters in the string are letters and there is at least one character, it returns true for each element, otherwise it returns false. isdecimal (a) For each element, if there are only decimal characters in the element, it returns True. isdigit (a) If all characters in the string are digits and there is at least one character, it returns true for each element, otherwise it returns false. islower (one) If all shell characters in the string are lowercase and there is at least one shell character, it returns true for each element, otherwise it returns false. isnumeric (a) For each element, if there are only numeric characters in the element, it returns True. isspace (a) If there are only space characters in the string and at least one character, it returns true for each element, otherwise it returns false. istitle (a) If the element is a string with a title and has at least one character, it returns true for each element, otherwise it returns false. isupper (one) If all shell characters in the string are uppercase and have at least one character, it returns true for each element, otherwise it returns false. rfind(a,sub[,start,end]) has one in each element, and returns the highest index in the string, where the child is found, so that the child contains [start, end within. rindex(a, sub[, start, end]) such as rfind, but ValueError will be raised when the substring sub cannot be found. startswith(a, prefix [, beginning, end]) returns a boolean array where the string element is a real prefix, otherwise false.
Convenience
chararray (shape [, itemsize, unicode,...]) provides a convenient view of arrays of strings and unicode values
Date and time support function
datetime_as_string(arr[,unit,timezone,...]) converts datetime array to string array. datetime_data(dtype, /) Get information about the step size of the date or time type.
Business day function
busdaycalendar ([weekly, holiday]) workday calendar object, which can effectively store information defining the effective number of days of the busday series of functions. is_busday(date[, perimeter, holiday,...]) calculates which given date is valid and which is not. busday_offset(date, offset[, roll,...]) first adjusts the date to the effective date roll according to the rules, and then applies the offset to the given date calculated within the effective date. busday_count(begindates, enddates[,...]) calculation
For details, refer to numpy's documentation