numpy 1.22.4 Pypi GitHub Homepage
Other Docs
NotesParametersReturnsBackRef
require(a, dtype=None, requirements=None, *, like=None)

This function is useful to be sure that an array with the correct flags is returned for passing to compiled code (perhaps through ctypes).

Notes

The returned array will be guaranteed to have the listed requirements by making a copy if needed.

Parameters

a : array_like

The object to be converted to a type-and-requirement-satisfying array.

dtype : data-type

The 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 list of str

The 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

Reference object to allow the creation of arrays which are not NumPy arrays. If an array-like passed in as like supports 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.

versionadded

Returns

out : ndarray

Array with specified requirements and type if given.

Return an ndarray of the provided type that satisfies requirements.

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.

Examples

>>> 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
See :

Back References

The following pages refer to to this document either explicitly or contain code examples using this.

numpy.ascontiguousarray numpy.asfortranarray numpy.core._asarray

Local connectivity graph

Hover to see nodes names; edges to Self not shown, Caped at 50 nodes.

Using a canvas is more power efficient and can get hundred of nodes ; but does not allow hyperlinks; , arrows or text (beyond on hover)

SVG is more flexible but power hungry; and does not scale well to 50 + nodes.

All aboves nodes referred to, (or are referred from) current nodes; Edges from Self to other have been omitted (or all nodes would be connected to the central node "self" which is not useful). Nodes are colored by the library they belong to, and scaled with the number of references pointing them


GitHub : /numpy/core/_asarray.py#22
type: <class 'function'>
Commit: