MCPcopy Create free account
hub / github.com/numpy/numpy / require

Function require

numpy/core/_asarray.py:29–131  ·  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

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

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