numpy 1.22.4 Pypi GitHub Homepage
Other Docs
NotesParametersReturns
isscalar(element)

Notes

If you need a stricter way to identify a numerical scalar, use isinstance(x, numbers.Number) , as that returns False for most non-numerical elements such as strings.

In most 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

<SubstitutionRef: 
   |value: '|``isscalar(x)``|``np.ndim(x) == 0``|'
   |>
+======================================+===============+===================+ | PEP 3141 numeric objects (including | True | True | | builtins) | | | +--------------------------------------+---------------+-------------------+ | builtin string and buffer objects | True | True | +--------------------------------------+---------------+-------------------+ | other builtin objects, like | False | True | | pathlib.Path , :None:None:`Exception`, | | | | the result of re.compile | | | +--------------------------------------+---------------+-------------------+ | third-party objects like | False | True | | matplotlib.figure.Figure | | | +--------------------------------------+---------------+-------------------+ | zero-dimensional numpy arrays | False | True | +--------------------------------------+---------------+-------------------+ | other numpy arrays | False | False | +--------------------------------------+---------------+-------------------+ | :None:None:`list`, :None:None:`tuple`, and other sequence | False | False | | objects | | | +--------------------------------------+---------------+-------------------+

Parameters

element : any

Input argument, can be of any type and shape.

Returns

val : bool

True if :None:None:`element` is a scalar type, False if it is not.

Returns True if the type of :None:None:`element` is a scalar type.

See Also

ndim

Get the number of dimensions of an array

Examples

>>> 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
See :

Local connectivity graph

Hover to see nodes names; edges to Self not shown, Caped at 50 nodes.

Using a canvas is more power efficient and can get hundred of nodes ; but does not allow hyperlinks; , arrows or text (beyond on hover)

SVG is more flexible but power hungry; and does not scale well to 50 + nodes.

All aboves nodes referred to, (or are referred from) current nodes; Edges from Self to other have been omitted (or all nodes would be connected to the central node "self" which is not useful). Nodes are colored by the library they belong to, and scaled with the number of references pointing them


GitHub : /numpy/core/numeric.py#1859
type: <class 'function'>
Commit: