numpy.isscalar(num) [source]
Returns True if the type of num is a scalar type.
| Parameters: | 
  |  
|---|---|
| Returns: | 
  |  
See also
ndim In almost all cases np.ndim(x) == 0 should be used instead of this function, as that will also return true for 0d arrays. This is how numpy overloads functions in the style of the dx arguments to gradient and the bins argument to histogram. Some key differences:
| x | isscalar(x) |  np.ndim(x) == 0 |  
|---|---|---|
| PEP 3141 numeric objects (including builtins) | True |  True |  
| builtin string and buffer objects | True |  True |  
other builtin objects, like pathlib.Path, Exception, the result of re.compile
 |  False |  True |  
third-party objects like matplotlib.figure.Figure
 |  False |  True |  
| zero-dimensional numpy arrays | False |  True |  
| other numpy arrays | False |  False |  
list, tuple, and other sequence objects |  False |  False |  
>>> np.isscalar(3.1)
True
>>> np.isscalar(np.array(3.1))
False
>>> np.isscalar([3.1])
False
>>> np.isscalar(False)
True
>>> np.isscalar('numpy')
True
 NumPy supports PEP 3141 numbers:
>>> from fractions import Fraction >>> np.isscalar(Fraction(5, 17)) True >>> from numbers import Number >>> np.isscalar(Number()) True
    © 2005–2019 NumPy Developers
Licensed under the 3-clause BSD License.
    https://docs.scipy.org/doc/numpy-1.17.0/reference/generated/numpy.isscalar.html