numpy.require(a, dtype=None, requirements=None)

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).


a : array_like

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

dtype : data-type

The required data-type (None is the default data-type – float64)

requirements : list of strings

The requirements list can be any of the following

  • ‘ENSUREARRAY’ (‘E’) - ensure that a base-class ndarray
  • ‘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 writeable array
  • ‘OWNDATA’ (‘O’) - ensure an array that owns its own data


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

Previous topic


Next topic


This Page

Quick search