MCPcopy
hub / github.com/numpy/numpy / isscalar

Function isscalar

numpy/_core/numeric.py:1911–1994  ·  view source on GitHub ↗

Returns True if the type of `element` is a scalar type. Parameters ---------- element : any Input argument, can be of any type and shape. Returns ------- val : bool True if `element` is a scalar type, False if it is not. See Also -------- n

(element)

Source from the content-addressed store, hash-verified

1909
1910@set_module('numpy')
1911def isscalar(element):
1912 """
1913 Returns True if the type of `element` is a scalar type.
1914
1915 Parameters
1916 ----------
1917 element : any
1918 Input argument, can be of any type and shape.
1919
1920 Returns
1921 -------
1922 val : bool
1923 True if `element` is a scalar type, False if it is not.
1924
1925 See Also
1926 --------
1927 ndim : Get the number of dimensions of an array
1928
1929 Notes
1930 -----
1931 If you need a stricter way to identify a *numerical* scalar, use
1932 ``isinstance(x, numbers.Number)``, as that returns ``False`` for most
1933 non-numerical elements such as strings.
1934
1935 In most cases ``np.ndim(x) == 0`` should be used instead of this function,
1936 as that will also return true for 0d arrays. This is how numpy overloads
1937 functions in the style of the ``dx`` arguments to `gradient` and
1938 the ``bins`` argument to `histogram`. Some key differences:
1939
1940 +------------------------------------+---------------+-------------------+
1941 | x |``isscalar(x)``|``np.ndim(x) == 0``|
1942 +====================================+===============+===================+
1943 | PEP 3141 numeric objects | ``True`` | ``True`` |
1944 | (including builtins) | | |
1945 +------------------------------------+---------------+-------------------+
1946 | builtin string and buffer objects | ``True`` | ``True`` |
1947 +------------------------------------+---------------+-------------------+
1948 | other builtin objects, like | ``False`` | ``True`` |
1949 | `pathlib.Path`, `Exception`, | | |
1950 | the result of `re.compile` | | |
1951 +------------------------------------+---------------+-------------------+
1952 | third-party objects like | ``False`` | ``True`` |
1953 | `matplotlib.figure.Figure` | | |
1954 +------------------------------------+---------------+-------------------+
1955 | zero-dimensional numpy arrays | ``False`` | ``True`` |
1956 +------------------------------------+---------------+-------------------+
1957 | other numpy arrays | ``False`` | ``False`` |
1958 +------------------------------------+---------------+-------------------+
1959 | `list`, `tuple`, and other | ``False`` | ``False`` |
1960 | sequence objects | | |
1961 +------------------------------------+---------------+-------------------+
1962
1963 Examples
1964 --------
1965 >>> import numpy as np
1966
1967 >>> np.isscalar(3.1)
1968 True

Callers 11

__getitem__Method · 0.90
__mul__Method · 0.90
__mul__Method · 0.90
__rmul__Method · 0.90
__pow__Method · 0.90
__truediv__Method · 0.90
__rtruediv__Method · 0.90
piecewiseFunction · 0.90
assert_equalFunction · 0.90
astypeFunction · 0.70

Calls

no outgoing calls

Tested by 1

Used in the wild real call sites across dependent graphs

searching dependent graphs…