Array creation routines

Ones and zeros

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

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

empty(shape[, dtype, order, device])

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

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

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

identity(n[, dtype, device])

Return the identity array.

ones(shape[, dtype, order, device])

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

ones_like(a[, dtype, order, device, out])

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

zeros(shape[, dtype, order, device])

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

zeros_like(a[, dtype, order, device, out])

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

full_like
empty_like

From existing data

array(object[, dtype, device])

Create an array.

copy(a[, out])

Return an array copy of the given object.

frombuffer
fromfunction
fromiter
fromstring
loadtxt

Creating record arrays (np.rec)

Note

np.rec is the preferred alias for np.core.records.

core.records.array
core.records.fromarrays
core.records.fromrecords
core.records.fromstring
core.records.fromfile

Creating character arrays (np.char)

Note

np.char is the preferred alias for np.core.defchararray.

core.defchararray.array
core.defchararray.asarray

Numerical ranges

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

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.

meshgrid(*xi, **kwargs)

Return coordinate matrices from coordinate vectors.

geomspace
mgrid
ogrid

Building matrices

tril(m[, k])

Lower triangle of an array.

diag
diagflat
tri
triu
vander