NumPy Logic functions: isscalar() function
numpy.isscalar() function
The isscalar() function is used to returns True if the type of num is a scalar type.
Syntax:
numpy.isscalar(num)
Version: 1.15.0
Parameter:
Name | Description | Required / Optional |
---|---|---|
num | Input argument, can be of any type and shape. any |
Required |
Returns:
val : bool - True if num is a scalar type, False if it is not.
NumPy.isscalar() method Example-1:
>>> import numpy as np
>>> np.isscalar(5.1)
Output:
True
NumPy.isscalar() method Example-2:
>>> import numpy as np
>>> np.isscalar([5.1])
Output:
False
NumPy.isscalar() method Example-3:
>>> import numpy as np
>>> np.isscalar(False)
Output:
True
NumPy.isscalar() method Example-4:
>>> import numpy as np
>>> np.isscalar('numpy')
Output:
True
NumPy supports PEP 3141 numbers:
NumPy.isscalar() method Example-5:
>>> import numpy as np
>>> from fractions import Fraction
>>> np.isscalar(Fraction(6, 15))
Output:
True
NumPy.isscalar() method Example-6:
>>> import numpy as np
>>> from numbers import Number
>>> np.isscalar(Number())
Output:
True
Python - NumPy Code Editor:
Previous: isrealobj() function
Next: logical_and() function
It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.
https://www.w3resource.com/numpy/logic-functions/isscalar.php
- Weekly Trends and Language Statistics
- Weekly Trends and Language Statistics