Array creation routines#

Ones and zeros#

empty(shape[, dtype, order])

Returns an array without initializing the elements.

empty_like(prototype[, dtype, order, subok, ...])

Returns a new array with same shape and dtype of a given array.

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

Returns a 2-D array with ones on the diagonals and zeros elsewhere.

identity(n[, dtype])

Returns a 2-D identity array.

ones(shape[, dtype, order])

Returns a new array of given shape and dtype, filled with ones.

ones_like(a[, dtype, order, subok, shape])

Returns an array of ones with same shape and dtype as a given array.

zeros(shape[, dtype, order])

Returns a new array of given shape and dtype, filled with zeros.

zeros_like(a[, dtype, order, subok, shape])

Returns an array of zeros with same shape and dtype as a given array.

full(shape, fill_value[, dtype, order])

Returns a new array of given shape and dtype, filled with a given value.

full_like(a, fill_value[, dtype, order, ...])

Returns a full array with same shape and dtype as a given array.

From existing data#

array(obj[, dtype, copy, order, subok, ...])

Creates an array on the current device.

asarray(a[, dtype, order, blocking])

Converts an object to array.

asanyarray(a[, dtype, order, blocking])

Converts an object to array.

ascontiguousarray(a[, dtype])

Returns a C-contiguous array.

copy(a[, order])

Creates a copy of a given array on the current device.

frombuffer(*args, **kwargs)

Interpret a buffer as a 1-dimensional array.

fromfile(*args, **kwargs)

Reads an array from a file.

fromfunction(*args, **kwargs)

Construct an array by executing a function over each coordinate.

fromiter(*args, **kwargs)

Create a new 1-dimensional array from an iterable object.

fromstring(*args, **kwargs)

A new 1-D array initialized from text data in a string.

loadtxt(*args, **kwargs)

Load data from a text file.

Numerical ranges#

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

Returns an array with evenly spaced values within a given interval.

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

Returns an array with evenly-spaced values within a given interval.

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

Returns an array with evenly-spaced values on a log-scale.

meshgrid(*xi, **kwargs)

Return coordinate matrices from coordinate vectors.

mgrid

Construct a multi-dimensional "meshgrid".

ogrid

Construct a multi-dimensional "meshgrid".

Building matrices#

diag(v[, k])

Returns a diagonal or a diagonal array.

diagflat(v[, k])

Creates a diagonal array from the flattened input.

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

Creates an array with ones at and below the given diagonal.

tril(m[, k])

Returns a lower triangle of an array.

triu(m[, k])

Returns an upper triangle of an array.

vander(x[, N, increasing])

Returns a Vandermonde matrix.