Skip to main content

NumPy Array Creation Methods

NumPy provides methods to create arrays, such as arange() for a range of numbers, linspace() for evenly spaced values, and zeros() and ones() for arrays filled with 0s or 1s.

creates an array with interval-based elements

creates new array of given shape filled with zeros

create evenly spaced array elements over interval

creates new array of given shape filled with ones

logspace() creates array with evenly spaced number

meshgrid() taken 1D arrays and returns 2D arrays

empty() creates new array without defining entries

copy() returns the copy of an array

full() creates an array filled with a given value

loadtxt() loads data from a text file

asarray() converts all array-like objects to array

diag() either forms or fetches diagonal of array

eye() creates 2D array with 1s(on diagonal) and 0s

frombuffer() interprets a buffer as a 1D array