Array creation routines#

From shape or value#

empty(shape[, dtype])

Return a new array of given shape and type, without initializing entries.

empty_like(prototype[, dtype])

Return a new array with the same shape and type as a given array.

eye(N[, M, k, dtype])

Return a 2-D array with ones on the diagonal and zeros elsewhere.

identity(n[, dtype])

Return the identity array.

ones(shape[, dtype])

Return a new array of given shape and type, filled with ones.

ones_like(a[, dtype, shape])

Return an array of ones with the same shape and type as a given array.

zeros(shape[, dtype])

Return a new array of given shape and type, filled with zeros.

zeros_like(a[, dtype, shape])

Return an array of zeros with the same shape and type as a given array.

full(shape, value[, dtype])

Return a new array of given shape and type, filled with fill_value.

full_like(a, value[, dtype, shape])

Return a full array with the same shape and type as a given array.

From existing data#

array(object[, dtype, copy])

Create an array.

asarray(a[, dtype])

Convert the input to an array.

copy(a)

Return an array copy of the given object.

copyto(dst, src[, casting, where])

Copies values from one array to another, broadcasting as necessary.

repeat(a, repeats[, axis])

Repeat elements of an array.

Numerical ranges#

arange([start,] stop[, step,][, dtype])

Return evenly spaced values within a given interval.

logspace(start, stop[, num, endpoint, base, ...])

Return numbers spaced evenly on a log scale. In linear space, the sequence starts at base ** start (base to the power of start) and ends with base ** stop (see endpoint below). :param start: base ** start is the starting value of the sequence. :type start: array_like :param stop: base ** stop is the final value of the sequence, unless endpoint is False. In that case, num + 1 values are spaced over the interval in log-space, of which all but the last (a sequence of length num) are returned. :type stop: array_like :param num: Number of samples to generate. Default is 50. :type num: int, optional :param endpoint: If true, stop is the last sample. Otherwise, it is not included. Default is True. :type endpoint: bool, optional :param base: The base of the log space. The step size between the elements in ln(samples) / ln(base) (or log_base(samples)) is uniform. Default is 10.0. :type base: array_like, optional :param dtype: The type of the output array. If dtype is not given, infer the data type from the other input arguments. :type dtype: data-type, optional :param axis: The axis in the result to store the samples. Relevant only if start or stop are array-like. By default (0), the samples will be along a new axis inserted at the beginning. Use -1 to get an axis at the end. :type axis: int, optional.

linspace(start, stop[, num, endpoint, ...])

Return evenly spaced numbers over a specified interval.

meshgrid(*xi[, copy, sparse, indexing])

Return a tuple of coordinate matrices from coordinate vectors.

Building matrices#

diag(v[, k])

Extract a diagonal or construct a diagonal array.

diagflat(v[, k])

Create a two-dimensional array with the flattened input as a diagonal.

tri(N[, M, k, dtype, like])

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.