From e2998f8b0dbedc9bc56530ff2fc682d72a0b84ff Mon Sep 17 00:00:00 2001 From: Pradeep Reddy Raamana Date: Fri, 23 Aug 2019 09:45:13 -0400 Subject: renamed the input arg to remove hint it is geared for numbers --- numpy/core/numeric.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'numpy/core/numeric.py') diff --git a/numpy/core/numeric.py b/numpy/core/numeric.py index 8ada87b9f..0b16ba03a 100644 --- a/numpy/core/numeric.py +++ b/numpy/core/numeric.py @@ -1772,19 +1772,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 -------- @@ -1843,9 +1843,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') -- cgit v1.2.1 From b79ee2ef3155b5b5beb37258845c281835e29324 Mon Sep 17 00:00:00 2001 From: Pradeep Reddy Raamana Date: Fri, 23 Aug 2019 09:45:58 -0400 Subject: help to identify a numeric scalar --- numpy/core/numeric.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'numpy/core/numeric.py') 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``| -- cgit v1.2.1