Methods for array creation in Numpy

FunctionDescription
empty()Return a new array of given shape and type, without initializing entries
empty_like()Return a new array with the same shape and type as a given array
eye()Return a 2-D array with ones on the diagonal and zeros elsewhere.
identity()Return the identity array
ones()Return a new array of given shape and type, filled with ones
ones_like()Return an array of ones with the same shape and type as a given array
zeros()Return a new array of given shape and type, filled with zeros
zeros_like()Return an array of zeros with the same shape and type as a given array
full_like()Return a full array with the same shape and type as a given array.
array()Create an array
asarray()Convert the input to an array
asanyarray()Convert the input to an ndarray, but pass ndarray subclasses through
ascontiguousarray()Return a contiguous array in memory (C order)
asmatrix()Interpret the input as a matrix
copy()Return an array copy of the given object
frombuffer()Interpret a buffer as a 1-dimensional array
fromfile()Construct an array from data in a text or binary file
fromfunction()Construct an array by executing a function over each coordinate
fromiter()Create a new 1-dimensional array from an iterable object
fromstring()A new 1-D array initialized from text data in a string
loadtxt()Load data from a text file
arange()Return evenly spaced values within a given interval
linspace()Return evenly spaced numbers over a specified interval
logspace()Return numbers spaced evenly on a log scale
geomspace()Return numbers spaced evenly on a log scale (a geometric progression)
meshgrid()Return coordinate matrices from coordinate vectors
mgrid()nd_grid instance which returns a dense multi-dimensional “meshgrid
ogrid()nd_grid instance which returns an open multi-dimensional “meshgrid
diag()Extract a diagonal or construct a diagonal array
diagflat()Create a two-dimensional array with the flattened input as a diagonal
tri()An array with ones at and below the given diagonal and zeros elsewhere
tril()Lower triangle of an array
triu()Upper triangle of an array
vander()Generate a Vandermonde matrix
mat()Interpret the input as a matrix
bmat()Build a matrix object from a string, nested sequence, or array


Numpy | Array Creation

In this article, we are going to explore numpy array creation technique.

Table of Content

  • Array creation using List :
  • Array creation using array functions
  • Methods for array creation in Numpy

Similar Reads

Array creation using List :

Arrays are used to store multiple values in one single variable.Python does not have built-in support for Arrays, but Python lists can be used instead....

Array creation using array functions

array(data type, value list) function is used to create an array with data type and value list specified in its arguments.np.zeros...

Array creation using numpy methods

NumPy offers several functions to create arrays with initial placeholder content. These minimize the necessity of growing arrays, an expensive operation. For example: np.zeros,np.empty etc....

Reshaping array

We can use reshape method to reshape an array. Consider an array with shape (a1, a2, a3, …, aN). We can reshape and convert it into another array with shape (b1, b2, b3, …, bM).The only required condition is: a1 x a2 x a3 … x aN = b1 x b2 x b3 … x bM . (i.e original size of array remains unchanged.)...

Methods for array creation in Numpy

FunctionDescriptionempty()Return a new array of given shape and type, without initializing entriesempty_like()Return a new array with the same shape and type as a given arrayeye()Return a 2-D array with ones on the diagonal and zeros elsewhere.identity()Return the identity arrayones()Return a new array of given shape and type, filled with onesones_like()Return an array of ones with the same shape and type as a given arrayzeros()Return a new array of given shape and type, filled with zeroszeros_like()Return an array of zeros with the same shape and type as a given arrayfull_like()Return a full array with the same shape and type as a given array.array()Create an arrayasarray()Convert the input to an arrayasanyarray()Convert the input to an ndarray, but pass ndarray subclasses throughascontiguousarray()Return a contiguous array in memory (C order)asmatrix()Interpret the input as a matrixcopy()Return an array copy of the given objectfrombuffer()Interpret a buffer as a 1-dimensional arrayfromfile()Construct an array from data in a text or binary filefromfunction()Construct an array by executing a function over each coordinatefromiter()Create a new 1-dimensional array from an iterable objectfromstring()A new 1-D array initialized from text data in a stringloadtxt()Load data from a text filearange()Return evenly spaced values within a given intervallinspace()Return evenly spaced numbers over a specified intervallogspace()Return numbers spaced evenly on a log scalegeomspace()Return numbers spaced evenly on a log scale (a geometric progression)meshgrid()Return coordinate matrices from coordinate vectorsmgrid()nd_grid instance which returns a dense multi-dimensional “meshgridogrid()nd_grid instance which returns an open multi-dimensional “meshgriddiag()Extract a diagonal or construct a diagonal arraydiagflat()Create a two-dimensional array with the flattened input as a diagonaltri()An array with ones at and below the given diagonal and zeros elsewheretril()Lower triangle of an arraytriu()Upper triangle of an arrayvander()Generate a Vandermonde matrixmat()Interpret the input as a matrixbmat()Build a matrix object from a string, nested sequence, or array...

Contact Us