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.)
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.
Shape of created array.
Any object that can be interpreted as a numpy data type. Default is numpy.float64.
Used to fill the array with data.
Offset of array data in buffer.
Strides of data in memory.
Row-major (C-style) or column-major (Fortran-style) order.
See also
arrayConstruct an array.
zerosCreate an array, each element of which is zero.
emptyCreate an array, but leave its allocated memory unchanged (i.e., it contains “garbage”).
dtypeCreate a data-type.
numpy.typing.NDArrayAn ndarray alias generic w.r.t. its dtype.type.
There are two modes of creating an array using __new__:
buffer is None, then only shape, dtype, and order are used.buffer is 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.
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')
array([[0.0e+000, 0.0e+000], # random
[ nan, 2.5e-323]])
Second mode:
>>> np.ndarray((2,), buffer=np.array([1,2,3]), ... offset=np.int_().itemsize, ... dtype=int) # offset = 1*itemsize, i.e. skip first element array([2, 3])
Tndarray
View of the transposed array.
databuffer
Python buffer object pointing to the start of the array’s data.
dtypedtype object
Data-type of the array’s elements.
flagsdict
Information about the memory layout of the array.
flatnumpy.flatiter object
A 1-D iterator over the array.
imagndarray
The imaginary part of the array.
realndarray
The real part of the array.
sizeint
Number of elements in the array.
itemsizeint
Length of one array element in bytes.
nbytesint
Total bytes consumed by the elements of the array.
ndimint
Number of array dimensions.
shapetuple of ints
Tuple of array dimensions.
stridestuple of ints
Tuple of bytes to step in each dimension when traversing an array.
ctypesctypes object
An object to simplify the interaction of the array with the ctypes module.
basendarray
Base object if memory is from some other object.
| Returns True if all elements evaluate to True. |
| Returns True if any of the elements of |
| Return indices of the maximum values along the given axis. |
| Return indices of the minimum values along the given axis. |
| Returns the indices that would partition this array. |
| Returns the indices that would sort this array. |
| Copy of the array, cast to a specified type. |
| Swap the bytes of the array elements |
| Use an index array to construct a new array from a set of choices. |
| Return an array whose values are limited to |
| Return selected slices of this array along given axis. |
| Complex-conjugate all elements. |
Return the complex conjugate, element-wise. | |
| Return a copy of the array. |
| Return the cumulative product of the elements along the given axis. |
| Return the cumulative sum of the elements along the given axis. |
| Return specified diagonals. |
| Refer to |
| Dump a pickle of the array to the specified file. |
| Returns the pickle of the array as a string. |
| Fill the array with a scalar value. |
| Return a copy of the array collapsed into one dimension. |
| Returns a field of the given array as a certain type. |
| Copy an element of an array to a standard Python scalar and return it. |
| Return the maximum along a given axis. |
| Returns the average of the array elements along given axis. |
| Return the minimum along a given axis. |
| Return the indices of the elements that are non-zero. |
| Partially sorts the elements in the array in such a way that the value of the element in k-th position is in the position it would be in a sorted array. |
| Return the product of the array elements over the given axis |
| Set |
| Return a flattened array. |
| Repeat elements of an array. |
| Returns an array containing the same data with a new shape. |
| Change shape and size of array in-place. |
| Return |
| Find indices where elements of |
| Put a value into a specified place in a field defined by a data-type. |
| Set array flags WRITEABLE, ALIGNED, WRITEBACKIFCOPY, respectively. |
| Sort an array in-place. |
| Remove axes of length one from |
| Returns the standard deviation of the array elements along given axis. |
| Return the sum of the array elements over the given axis. |
| Return a view of the array with |
| Return an array formed from the elements of |
| For Array API compatibility. |
| Construct Python bytes containing the raw data bytes in the array. |
| Write array to a file as text or binary (default). |
| Return the array as an |
| Return the sum along diagonals of the array. |
| Returns a view of the array with axes transposed. |
| Returns the variance of the array elements, along given axis. |
| New view of array with the same data. |
© 2005–2024 NumPy Developers
Licensed under the 3-clause BSD License.
https://numpy.org/doc/2.4/reference/generated/numpy.ndarray.html