MCPcopy
hub / github.com/numpy/numpy / require

Function require

numpy/_core/_asarray.py:24–127  ·  view source on GitHub ↗

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). Parameters ---------- a : array_like The object to be conve

(a, dtype=None, requirements=None, *, like=None)

Source from the content-addressed store, hash-verified

22@finalize_array_function_like
23@set_module('numpy')
24def require(a, dtype=None, requirements=None, *, like=None):
25 """
26 Return an ndarray of the provided type that satisfies requirements.
27
28 This function is useful to be sure that an array with the correct flags
29 is returned for passing to compiled code (perhaps through ctypes).
30
31 Parameters
32 ----------
33 a : array_like
34 The object to be converted to a type-and-requirement-satisfying array.
35 dtype : data-type
36 The required data-type. If None preserve the current dtype. If your
37 application requires the data to be in native byteorder, include
38 a byteorder specification as a part of the dtype specification.
39 requirements : str or sequence of str
40 The requirements list can be any of the following
41
42 * 'F_CONTIGUOUS' ('F') - ensure a Fortran-contiguous array
43 * 'C_CONTIGUOUS' ('C') - ensure a C-contiguous array
44 * 'ALIGNED' ('A') - ensure a data-type aligned array
45 * 'WRITEABLE' ('W') - ensure a writable array
46 * 'OWNDATA' ('O') - ensure an array that owns its own data
47 * 'ENSUREARRAY', ('E') - ensure a base array, instead of a subclass
48 ${ARRAY_FUNCTION_LIKE}
49
50 .. versionadded:: 1.20.0
51
52 Returns
53 -------
54 out : ndarray
55 Array with specified requirements and type if given.
56
57 See Also
58 --------
59 asarray : Convert input to an ndarray.
60 asanyarray : Convert to an ndarray, but pass through ndarray subclasses.
61 ascontiguousarray : Convert input to a contiguous array.
62 asfortranarray : Convert input to an ndarray with column-major
63 memory order.
64 ndarray.flags : Information about the memory layout of the array.
65
66 Notes
67 -----
68 The returned array will be guaranteed to have the listed requirements
69 by making a copy if needed.
70
71 Examples
72 --------
73 >>> import numpy as np
74 >>> x = np.arange(6).reshape(2,3)
75 >>> x.flags
76 C_CONTIGUOUS : True
77 F_CONTIGUOUS : False
78 OWNDATA : False
79 WRITEABLE : True
80 ALIGNED : True
81 WRITEBACKIFCOPY : False

Callers

nothing calls this directly

Calls 4

arrayFunction · 0.90
asanyarrayFunction · 0.85
upperMethod · 0.80
copyMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…