bundles / numpy latest / numpy / ndarray
GenericAlias
numpy:ndarray
source: /opt/hostedtoolcache/Python/3.14.5/x64/lib/python3.14/types.py
Signature
def ndarray ( shape , dtype = <class 'float'> , buffer = None , offset = 0 , strides = None , order = None ) Summary
An array object represents a multidimensional, homogeneous array of fixed-size items. An associated data-type object describes the format of each element in the array (its byte-order, how many bytes it occupies in memory, whether it is an integer, a floating point number, or something else, etc.)
Extended Summary
Arrays should be constructed using array, zeros or empty (refer to the See Also section below). The parameters given here refer to a low-level method (ndarray(...)) for instantiating an array.
For more information, refer to the numpy module and examine the methods and attributes of an array.
Parameters
(for the __new__ method; see Notes below)shape: tuple of intsShape of created array.
dtype: data-type, optionalAny object that can be interpreted as a numpy data type. Default is numpy.float64.
buffer: object exposing buffer interface, optionalUsed to fill the array with data.
offset: int, optionalOffset of array data in buffer.
strides: tuple of ints, optionalStrides of data in memory.
order: {'C', 'F'}, optionalRow-major (C-style) or column-major (Fortran-style) order.
Attributes
T: ndarrayTranspose of the array.
data: bufferThe array's elements, in memory.
dtype: dtype objectDescribes the format of the elements in the array.
flags: dictDictionary containing information related to memory use, e.g., 'C_CONTIGUOUS', 'OWNDATA', 'WRITEABLE', etc.
flat: numpy.flatiter objectFlattened version of the array as an iterator. The iterator allows assignments, e.g.,
x.flat = 3(Seendarray.flatfor assignment examples; TODO).imag: ndarrayImaginary part of the array.
real: ndarrayReal part of the array.
size: intNumber of elements in the array.
itemsize: intThe memory use of each array element in bytes.
nbytes: intThe total number of bytes required to store the array data, i.e.,
itemsize * size.ndim: intThe array's number of dimensions.
shape: tuple of intsShape of the array.
strides: tuple of intsThe step-size required to move from one element to the next in memory. For example, a contiguous
(3, 4)array of typeint16in C-order has strides(8, 2). This implies that to move from element to element in memory requires jumps of 2 bytes. To move from row-to-row, one needs to jump 8 bytes at a time (2 * 4).ctypes: ctypes objectClass containing properties of the array needed for interaction with ctypes.
base: ndarrayIf the array is a view into another array, that array is its base (unless that array is also a view). The base array is where the array data is actually stored.
Notes
There are two modes of creating an array using __new__:
If
bufferis None, then onlyshape,dtype, andorderare used.If
bufferis an object exposing the buffer interface, then all keywords are interpreted.
No __init__ method is needed because the array is fully initialized after the __new__ method.
Examples
These examples illustrate the low-level `ndarray` constructor. Refer to the `See Also` section above for easier ways of constructing an ndarray. First mode, `buffer` is None:import numpy as np
✓np.ndarray(shape=(2,2), dtype=float, order='F')
✗np.ndarray((2,), buffer=np.array([1,2,3]), offset=np.int_().itemsize, dtype=int) # offset = 1*itemsize, i.e. skip first element✓
See also
- array
Construct an array.
- dtype
Create a data-type.
- empty
Create an array, but leave its allocated memory unchanged (i.e., it contains "garbage").
- numpy.typing.NDArray
An ndarray alias
generic <generic type>w.r.t. itsdtype.type <numpy.dtype.type>.- zeros
Create an array, each element of which is zero.
Aliases
-
numpy.ndarray -
numpy.typing.NDArray
Referenced by
This package
- reference:c-api:data_memory
- reference:maskedarray.baseclass
- reference:maskedarray.generic
- reference:thread_safety
- release:1.21.0-notes
- release:1.25.0-notes
- user:basics.copies
- user:whatisnumpy
- reference:c-api:data_memory
- reference:maskedarray.baseclass
- reference:maskedarray.generic
- reference:thread_safety
- release:1.21.0-notes
- release:1.25.0-notes
- user:basics.copies
- user:whatisnumpy
- reference:c-api:data_memory
- reference:maskedarray.baseclass
- reference:maskedarray.generic
- release:1.21.0-notes
- release:1.25.0-notes
- user:basics.copies
- user:whatisnumpy
Other packages
- astropy astropy.io.fits.column:Column.__init__
- astropy astropy.io.fits.fitsrec:FITS_rec
- astropy astropy.io.fits.hdu.hdulist:HDUList.fromstring
- astropy astropy.io.fits.hdu.table:_TableLikeHDU.from_columns
- astropy astropy.io.fits.util:_array_to_file_like
- astropy astropy.utils.shapes:NDArrayShapeMethods
- astropy astropy.utils.shapes:ShapedLikeNDArray
- scipy tutorial:arpack
- scipy tutorial:linalg
- scipy tutorial:sparse
- scipy scipy.datasets
- scipy scipy.io.matlab._mio5_params:MatlabFunction
- scipy scipy.io.matlab._mio5_params:MatlabObject
- scipy scipy.io.matlab._mio5_params:MatlabOpaque
- scipy scipy.linalg.interpolative
- scipy scipy.linalg.interpolative:estimate_rank
- scipy scipy.linalg.interpolative:interp_decomp
- scipy scipy.linalg.interpolative:svd