NumPy: require() function
numpy.require() function
The require() function returns 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).
Syntax:
numpy.require(a, dtype=None, requirements=None)
Version: 1.15.0
Parameter:
Name | Description | Required / Optional |
---|---|---|
a | The object to be converted to a type-and-requirement-satisfying array. | Required |
dtype | 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. | Required |
requirements | The requirements list can be any of the following
|
Required |
Return value:
out : ndarray - Array interpretation of a. No copy is performed if the input is already an ndarray. If a is a subclass of ndarray, a base class ndarray is returned.
Raises: ValueError - Raises ValueError if a contains NaN (Not a Number) or Inf (Infinity).
Example-1: numpy.require() function
>>> import numpy as np
>>> a = np.arange(9).reshape(3,3)
>>> a.flags
C_CONTIGUOUS : True
F_CONTIGUOUS : False
OWNDATA : False
WRITEABLE : True
ALIGNED : True
UPDATEIFCOPY : False
Example-2: numpy.require() function
>>> import numpy as np
>>> b = np.require(a, dtype=np.float32, requirements=['A', 'O', 'W', 'F'])
>>> b.flags
C_CONTIGUOUS : False
F_CONTIGUOUS : True
OWNDATA : True
WRITEABLE : True
ALIGNED : True
UPDATEIFCOPY : False
Python - NumPy Code Editor:
Previous: asscalar()
Next: Joining arrays concatenate()
- New Content published on w3resource:
- HTML-CSS Practical: Exercises, Practice, Solution
- Java Regular Expression: Exercises, Practice, Solution
- Scala Programming Exercises, Practice, Solution
- Python Itertools exercises
- Python Numpy exercises
- Python GeoPy Package exercises
- Python Pandas exercises
- Python nltk exercises
- Python BeautifulSoup exercises
- Form Template
- Composer - PHP Package Manager
- PHPUnit - PHP Testing
- Laravel - PHP Framework
- Angular - JavaScript Framework
- Vue - JavaScript Framework
- Jest - JavaScript Testing Framework