Array creation routines

Ones and zeros

methoddescription
emptyopen in new window(shape[, dtype, order])Return a new array of given shape and type, without initializing entries.
empty_likeopen in new window(prototype[, dtype, order, subok, …])Return a new array with the same shape and type as a given array.
eyeopen in new window(N[, M, k, dtype, order])Return a 2-D array with onesopen in new window on the diagonal and zerosopen in new window elsewhere.
identityopen in new window(n[, dtype])Return the identity array.
ones(shape[, dtype, order])Return a new array of given shape and type, filled with ones.
ones_likeopen in new window(a[, dtype, order, subok, shape])Return an array of ones with the same shape and type as a given array.
zeros(shape[, dtype, order])Return a new array of given shape and type, filled with zeros.
zeros_likeopen in new window(a[, dtype, order, subok, shape])Return an array of zeros with the same shape and type as a given array.
fullopen in new window(shape, fill_value[, dtype, order])Return a new array of given shape and type, filled with fill_value.
full_likeopen in new window(a, fill_value[, dtype, order, …])Return a full array with the same shape and type as a given array.

From existing data

methoddescription
arrayopen in new window(object[, dtype, copyopen in new window, order, subok, ndmin])Create an array.
asarrayopen in new window(a[, dtype, order])Convert the input to an array.
asanyarrayopen in new window(a[, dtype, order])Convert the input to an ndarray, but pass ndarray subclasses through.
ascontiguousarrayopen in new window(a[, dtype])Return a contiguous array (ndim >= 1) in memory (C order).
asmatrixopen in new window(data[, dtype])Interpret the input as a matrix.
copy(a[, order])Return an array copy of the given object.
frombufferopen in new window(buffer[, dtype, count, offset])Interpret a buffer as a 1-dimensional array.
fromfileopen in new window(file[, dtype, count, sep, offset])Construct an array from data in a text or binary file.
fromfunctionopen in new window(function, shape, **kwargs)Construct an array by executing a function over each coordinate.
fromiteropen in new window(iterable, dtype[, count])Create a new 1-dimensional array from an iterable object.
fromstringopen in new window(string[, dtype, count, sep])A new 1-D array initialized from text data in a string.
loadtxtopen in new window(fname[, dtype, comments, delimiter, …])Load data from a text file.

Creating record arrays (numpy.rec)

Note

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

methoddescription
core.records.arrayopen in new window(obj[, dtype, shape, …])Construct a record array from a wide-variety of objects.
core.records.fromarraysopen in new window(arrayList[, dtype, …])create a record array from a (flat) list of arrays
core.records.fromrecordsopen in new window(recList[, dtype, …])create a recarray from a list of records in text form
core.records.fromstringopen in new window(datastring[, dtype, …])create a (read-only) record array from binary data contained in a string
core.records.fromfileopen in new window(fd[, dtype, shape, …])Create an array from binary file data

Creating character arrays (numpy.char)

Note

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

methoddescription
core.defchararray.arrayopen in new window(obj[, itemsize, …])Create a chararray.
core.defchararray.asarrayopen in new window(obj[, itemsize, …])Convert the input to a chararray, copying the data only if necessary.

Numerical ranges

methoddescription
arangeopen in new window([start,] stop[, step,][, dtype])Return evenly spaced values within a given interval.
linspaceopen in new window(start, stop[, num, endpoint, …])Return evenly spaced numbers over a specified interval.
logspaceopen in new window(start, stop[, num, endpoint, base, …])Return numbers spaced evenly on a log scale.
geomspaceopen in new window(start, stop[, num, endpoint, …])Return numbers spaced evenly on a log scale (a geometric progression).
meshgridopen in new window(*xi, **kwargs)Return coordinate matrices from coordinate vectors.
mgridopen in new windownd_grid instance which returns a dense multi-dimensional “meshgrid”.
ogridopen in new windownd_grid instance which returns an open multi-dimensional “meshgrid”.

Building matrices

methoddescription
diagopen in new window(v[, k])Extract a diagonal or construct a diagonal array.
diagflatopen in new window(v[, k])Create a two-dimensional array with the flattened input as a diagonal.
triopen in new window(N[, M, k, dtype])An array with ones at and below the given diagonal and zeros elsewhere.
trilopen in new window(m[, k])Lower triangle of an array.
triuopen in new window(m[, k])Upper triangle of an array.
vanderopen in new window(x[, N, increasing])Generate a Vandermonde matrix.

The Matrix class

methoddescription
matopen in new window(data[, dtype])Interpret the input as a matrix.
bmatopen in new window(obj[, ldict, gdict])Build a matrix object from a string, nested sequence, or array.