diff options
author | Pradeep Reddy Raamana <raamana@gmail.com> | 2019-08-23 09:45:58 -0400 |
---|---|---|
committer | Pradeep Reddy Raamana <raamana@gmail.com> | 2019-08-23 09:45:58 -0400 |
commit | b79ee2ef3155b5b5beb37258845c281835e29324 (patch) | |
tree | 0fa388aaaf479a66fe3b2dbdf331479d2b784323 /numpy/core/numeric.py | |
parent | e2998f8b0dbedc9bc56530ff2fc682d72a0b84ff (diff) | |
download | numpy-b79ee2ef3155b5b5beb37258845c281835e29324.tar.gz |
help to identify a numeric scalar
Diffstat (limited to 'numpy/core/numeric.py')
-rw-r--r-- | numpy/core/numeric.py | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/numpy/core/numeric.py b/numpy/core/numeric.py index 0b16ba03a..7ee69d8e0 100644 --- a/numpy/core/numeric.py +++ b/numpy/core/numeric.py @@ -1792,10 +1792,14 @@ def isscalar(element): Notes ----- - 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: + 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 |``isscalar(x)``|``np.ndim(x) == 0``| |