创建数组
方法 | 描述 |
---|---|
empty(shape[, dtype, order]) | 根据指定的shape和dtype创建数组 |
empty_like(a[, dtype, order, subok]) | 根据已知数组的shape和dtype创建数组 |
eye(N[, M, k, dtype, order]) | 创建对角线为1的二维数组 |
identity(n[, dtype]) | 创建单位阵 |
ones(shape[, dtype, order]) | 根据指定shape创建全为1的数组 |
ones_like(a[, dtype, order, subok]) | 根据已知数组的shape创建全为1的数组 |
zeros(shape[, dtype, order]) | 创建全部为0的数组 |
zeros_like(a[, dtype, order, subok]) | 根据已知的数组创建全为0的数组 |
full(shape, fill_value[, dtype, order]) | 根据shape,fill_value创建数组 |
full_like(a, fill_value[, dtype, order, subok]) | 根据已知数组的shape创建权威fill_value的数组 |
从已有数据中创建数组
方法 | 描述 |
---|---|
array(object[, dtype, copy, order, subok, ndmin]) | 创建一个数组,参数为list |
asarray(a[, dtype, order]) | Convert the input to an array. |
asanyarray(a[, dtype, order]) | Convert the input to an ndarray, but pass ndarray subclasses through. |
ascontiguousarray(a[, dtype]) | Return a contiguous array in memory (C order). |
asmatrix(data[, dtype]) | Interpret the input as a matrix. |
copy(a[, order]) | Return an array copy of the given object. |
frombuffer(buffer[, dtype, count, offset]) | Interpret a buffer as a 1-dimensional array. |
fromfile(file[, dtype, count, sep]) | Construct an array from data in a text or binary file. |
fromfunction(function, shape, **kwargs) | Construct an array by executing a function over each coordinate. |
fromiter(iterable, dtype[, count]) | Create a new 1-dimensional array from an iterable object. |
fromstring(string[, dtype, count, sep]) | 从字符串中创建一维数组 |
loadtxt(fname[, dtype, comments, delimiter, …]) | Load data from a text file. |
Numerical ranges
方法 | 描述 |
---|---|
arange([start,] stop[, step,][, dtype]) | Return evenly spaced values within a given interval. |
linspace(start, stop[, num, endpoint, …]) | Return evenly spaced numbers over a specified interval. |
logspace(start, stop[, num, endpoint, base, …]) | Return numbers spaced evenly on a log scale. |
geomspace(start, stop[, num, endpoint, dtype]) | Return numbers spaced evenly on a log scale (a geometric progression). |
meshgrid(*xi, **kwargs) | Return coordinate matrices from coordinate vectors. |
mgrid | nd_grid instance which returns a dense multi-dimensional “meshgrid”. |
ogrid | nd_grid instance which returns an open multi-dimensional “meshgrid”. |
创建矩阵
方法 | 描述 |
---|---|
diag(v[, k]) | 提取或创建对角矩阵 |
diagflat(v[, k]) | Create a two-dimensional array with the flattened input as a diagonal. |
tri(N[, M, k, dtype]) | An array with ones at and below the given diagonal and zeros elsewhere. |
tril(m[, k]) | Lower triangle of an array. |
triu(m[, k]) | Upper triangle of an array. |
vander(x[, N, increasing]) | Generate a Vandermonde matrix. |
创建矩阵对象
方法 | 描述 |
---|---|
mat(data[, dtype]) | Interpret the input as a matrix. |
bmat(obj[, ldict, gdict]) | Build a matrix object from a string, nested sequence, or array. |