summaryrefslogtreecommitdiff
path: root/numpy/core/numeric.py
diff options
context:
space:
mode:
authorMatti Picus <matti.picus@gmail.com>2019-10-16 00:33:30 +0300
committerGitHub <noreply@github.com>2019-10-16 00:33:30 +0300
commit2287cd96889d3ee509cae2aab9e28da348c556a0 (patch)
treeacf5eb399acedaafc4b6b29a1feeeea9c299bc3f /numpy/core/numeric.py
parentdc20ec8c857bc1f1b717b56f3a5c64dbf31f16ac (diff)
parentb79ee2ef3155b5b5beb37258845c281835e29324 (diff)
downloadnumpy-2287cd96889d3ee509cae2aab9e28da348c556a0.tar.gz
Merge pull request #14342 from raamana/is_scalar_docs
DOC: Improve documentation of `isscalar`.
Diffstat (limited to 'numpy/core/numeric.py')
-rw-r--r--numpy/core/numeric.py26
1 files changed, 15 insertions, 11 deletions
diff --git a/numpy/core/numeric.py b/numpy/core/numeric.py
index b5568fd86..750f69db8 100644
--- a/numpy/core/numeric.py
+++ b/numpy/core/numeric.py
@@ -1784,19 +1784,19 @@ def _frombuffer(buf, dtype, shape, order):
@set_module('numpy')
-def isscalar(num):
+def isscalar(element):
"""
- Returns True if the type of `num` is a scalar type.
+ Returns True if the type of `element` is a scalar type.
Parameters
----------
- num : any
+ element : any
Input argument, can be of any type and shape.
Returns
-------
val : bool
- True if `num` is a scalar type, False if it is not.
+ True if `element` is a scalar type, False if it is not.
See Also
--------
@@ -1804,10 +1804,14 @@ def isscalar(num):
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``|
@@ -1855,9 +1859,9 @@ def isscalar(num):
True
"""
- return (isinstance(num, generic)
- or type(num) in ScalarType
- or isinstance(num, numbers.Number))
+ return (isinstance(element, generic)
+ or type(element) in ScalarType
+ or isinstance(element, numbers.Number))
@set_module('numpy')