bundles / numpy latest / numpy / require
_ArrayFunctionDispatcher
numpy:require
source: /dev/numpy/build-install/usr/lib/python3.14/site-packages/numpy/_core/_asarray.py :22
Signature
def require ( a , dtype = None , requirements = None , * , like = None ) Summary
Return an ndarray of the provided type that satisfies requirements.
Extended Summary
This function is useful to be sure that an array with the correct flags is returned for passing to compiled code (perhaps through ctypes).
Parameters
a: array_likeThe object to be converted to a type-and-requirement-satisfying array.
dtype: data-typeThe required data-type. If None preserve the current dtype. If your application requires the data to be in native byteorder, include a byteorder specification as a part of the dtype specification.
requirements: str or sequence of strThe requirements list can be any of the following
'F_CONTIGUOUS' ('F') - ensure a Fortran-contiguous array
'C_CONTIGUOUS' ('C') - ensure a C-contiguous array
'ALIGNED' ('A') - ensure a data-type aligned array
'WRITEABLE' ('W') - ensure a writable array
'OWNDATA' ('O') - ensure an array that owns its own data
'ENSUREARRAY', ('E') - ensure a base array, instead of a subclass
like: array_like, optionalReference object to allow the creation of arrays which are not NumPy arrays. If an array-like passed in as
likesupports the__array_function__protocol, the result will be defined by it. In this case, it ensures the creation of an array object compatible with that passed in via this argument.
Returns
out: ndarrayArray with specified requirements and type if given.
Notes
The returned array will be guaranteed to have the listed requirements by making a copy if needed.
Examples
import numpy as np x = np.arange(6).reshape(2,3)✓
x.flags
✗y = np.require(x, dtype=np.float32, requirements=['A', 'O', 'W', 'F'])
✓y.flags
✗See also
- asanyarray
Convert to an ndarray, but pass through ndarray subclasses.
- asarray
Convert input to an ndarray.
- ascontiguousarray
Convert input to a contiguous array.
- asfortranarray
Convert input to an ndarray with column-major memory order.
- ndarray.flags
Information about the memory layout of the array.
Aliases
-
numpy.require -
numpy._core._asarray._require_with_like