BetterDocs
Home
Docs

Creation of NumPy Arrays

From existing data-
MethodDescription
np.array (object, dtype=None, *, copy=True, order='K', subok=False, ndmin=0, like=None)Create an array from that data passed to object.
np.asarray (a, dtype=None, order='K', *, device=None, copy=True, like=None)Create an array from the data passed to a.
np.frombuffer (buffer, dtype=np.float64, count=-1, offset=0, *, like=None)Interpret a buffer as a 1-dimensional array.
np.from_dlpack (x, /, *, device=None, copy=None)Create a NumPy array from an object implementing the __dlpack__ protocol.
np.fromfile (file, dtype=np.float64, count=-1, sep='', offset=0, *, like=None)Construct an array from data in a text or binary file.
np.fromfunction (function, shape, *, dtype=np.float64, like=None)Construct an array by executing a function over each coordinate.
np.fromiter (iter, dtype, count=-1, *, like=None)Create a new 1-dimensional array from an iterable object.
np.fromstring (string, dtype=np.float64, count=-1, *, sep, like=None)A new 1-D array initialized from text data in a string.
np.loadtxt (fname, dtype=np.float64, comments='#', delimiter=' ', converters=None, skiprows=0, usecols=None, unpack=False, ndmin=0, encoding=None, max_rows=None, *, quotechar=None, like=None)Load data from a text file.
From shape or value-
MethodDescription
np.empty (shape, dtype=np.float64, order='C', *, device=None, like=None)Return a new array of given shape and type, without initializing entries.
np.zeros (shape, dtype=np.float64, order='C', *, like=None)Creates a array of the entered shape filled with zeros.
np.ones (shape, dtype=np.float64, order='C', *, like=None)Creates a array of the entered shape filled with ones.
np.eye (N, M=None, k=0, dtype=np.float64, order='C', *, device=None, like=None)Return a 2-D array with ones on the diagonal and zeros elsewhere.
np.identity (n, dtype=np.float64, *, like=None)Return the identity array.
np.full (shape, fill_value, dtype=None, order='C', *, device=None, like=None)Return a new array of given shape and type, filled with fill_value.
np.empty_like (prototype, dtype=None, order='K', subok=True, shape=None, *, device=None)Return a new array with the same shape and type as a given array.
np.zeros_like (a, dtype=None, order='K', subok=True, shape=None, *, device=None)Return an array of zeros with the same shape and type as a given array.Return an array of zeros with the same shape and type as a given array.
np.ones_like (a, dtype=None, order='K', subok=True, shape=None, *, device=None)Return an array of ones with the same shape and type as a given array.
np.full_like (a, fill_value, dtype=None, order='K', subok=True, shape=None, *, device=None)Return a full array with the same shape and type as a given array.
From record arrays-
MethodDescription
np.rec.array (obj, dtype=None, shape=None, offset=0, strides=None, formats=None, names=None, titles=None, aligned=False, byteorder=None, copy=True)Construct a record array from a wide-variety of objects.
From ranges-
MethodDescription
np.arange ([start, ]stop,[step, ]dtype=None, *, device=None, like=None)Creates a array of values within a specified range.
np.linspace (start, stop, num=50, endpoint=True, retstep=False, dtype=np.float64, axis=0, *, device=None)Return evenly spaced numbers over a specified interval.
np.logspace (start, stop, num=50, endpoint=True, base=10.0, dtype=np.float64, axis=0)Return numbers spaced evenly on a log scale.
np.geomspace (start, stop, num=50, endpoint=True, dtype=np.float64, axis=0)Return numbers spaced evenly on a log scale (a geometric progression).
np.meshgrid (*xi, copy=True, sparse=False, indexing='xy')Return a tuple of coordinate matrices from coordinate vectors.
np.mgrid An instance which returns a dense multi-dimensional "meshgrid".
np.ogrid An instance which returns an open multi-dimensional "meshgrid".
Building matrices-
MethodDescription
np.diag (v, k=0)Extract a diagonal or construct a diagonal array.
np.diagflat (v, k=0)Create a two-dimensional array with the flattened input as a diagonal.
np.tri (N, M=None, k=0, dtype=np.float64, *,like=None)An array with ones at and below the given diagonal and zeros elsewhere.
np.tril (m, k=0)Lower triangle of an array.
np.triu (m, k=0)Upper triangle of an array.
np.vander (x, N=None, increasing=False)Generate a Vandermonde matrix.

Logo

BetterDocs

Support

EmailDiscordForms

Documentations

Python

Company

AboutDocs

Policies

Terms of ServicePrivacy Policy