Functions in the as*array family that promote array-likes into arrays.
require
fits this category despite its name not matching this pattern.
Function | _require_dispatcher |
Undocumented |
Function | require |
Return an ndarray of the provided type that satisfies requirements. |
Variable | _require_with_like |
Undocumented |
Return an ndarray of the provided type that satisfies requirements.
This function is useful to be sure that an array with the correct flags is returned for passing to compiled code (perhaps through ctypes).
The requirements list can be any of the following
${ARRAY_FUNCTION_LIKE}
New in version 1.20.0.
asarray : Convert input to an ndarray. asanyarray : Convert to an ndarray, but pass through ndarray subclasses. 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.
The returned array will be guaranteed to have the listed requirements by making a copy if needed.
>>> x = np.arange(6).reshape(2,3) >>> x.flags C_CONTIGUOUS : True F_CONTIGUOUS : False OWNDATA : False WRITEABLE : True ALIGNED : True WRITEBACKIFCOPY : False UPDATEIFCOPY : False
>>> y = np.require(x, dtype=np.float32, requirements=['A', 'O', 'W', 'F']) >>> y.flags C_CONTIGUOUS : False F_CONTIGUOUS : True OWNDATA : True WRITEABLE : True ALIGNED : True WRITEBACKIFCOPY : False UPDATEIFCOPY : False