numpy.require(a,dtype=None,requirements=None)[source]¶Return an ndarray of the provided type that satisfies requirements.
This function is useful to be sure that an array with the correct flagsis returned for passing to compiled code (perhaps through ctypes).
| Parameters: |
|
|---|
See also
asarrayasanyarrayascontiguousarrayasfortranarrayndarray.flagsNotes
The returned array will be guaranteed to have the listed requirementsby making a copy if needed.
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