All over the numpy code base you find things like:

def func_for_scalars_or_vectors(x):
    x = np.asarray(x)
    scalar_input = False
    if x.ndim == 0:
        x = x[None]  # Makes x 1D
        scalar_input = True

    # The magic happens here

    if scalar_input:
        return np.squeeze(ret)
    return ret
Answer from Jaime on Stack Overflow
🌐
NumPy
numpy.org › doc › stable › reference › arrays.scalars.html
Scalars — NumPy v2.4 Manual
Abstract base class of all complex number scalar types that are made up of floating-point numbers. ... Complex number type composed of two single-precision floating-point numbers. ... Complex number type composed of two double-precision floating-point numbers, compatible with Python complex.
🌐
GeeksforGeeks
geeksforgeeks.org › python › numpy-isscalar-python
numpy.isscalar() in Python - GeeksforGeeks
February 1, 2024 - The `numpy.isscalar()` is a function in the NumPy library of Python that is used to determine whether a given input is a scalar or not. A scalar is a single value, as opposed to an array or a more complex data structure.
🌐
Databricks
docs.databricks.com › developers › user-defined functions (udfs) › python scalar udfs
User-defined scalar functions - Python | Databricks on AWS
February 2, 2026 - This article contains Python user-defined function (UDF) examples. It shows how to register UDFs, how to invoke UDFs, and provides caveats about evaluation order of subexpressions in Spark SQL. In Databricks Runtime 12.2 LTS and below, Python UDFs and Pandas UDFs are not supported on Unity Catalog compute that uses standard access mode. Scalar Python UDFs and Pandas UDFs are supported in Databricks Runtime 13.3 LTS and above for all access modes.
Top answer
1 of 4
54

A NumPy scalar is any object which is an instance of np.generic or whose type is in np.ScalarType:

In [12]: np.ScalarType
Out[13]:
(int,
 float,
 complex,
 long,
 bool,
 str,
 unicode,
 buffer,
 numpy.int16,
 numpy.float16,
 numpy.int8,
 numpy.uint64,
 numpy.complex192,
 numpy.void,
 numpy.uint32,
 numpy.complex128,
 numpy.unicode_,
 numpy.uint32,
 numpy.complex64,
 numpy.string_,
 numpy.uint16,
 numpy.timedelta64,
 numpy.bool_,
 numpy.uint8,
 numpy.datetime64,
 numpy.object_,
 numpy.int64,
 numpy.float96,
 numpy.int32,
 numpy.float64,
 numpy.int32,
 numpy.float32)

This definition comes from looking at the source code for np.isscalar:

def isscalar(num):
    if isinstance(num, generic):
        return True
    else:
        return type(num) in ScalarType

Note that you can test if something is a scalar by using np.isscalar:

>>> np.isscalar(3.1)
True

>>> np.isscalar([3.1])
False

>>> np.isscalar(False)
True

How do we know what we know?

I like learning how people know what they know—more than the answers themselves. So let me try to explain where the above answer comes from.

Having the right tools can help you figure out things like this for yourself.

I found this out by using IPython. Using its TAB-completion feature, typing

In [19]: import numpy as np
In [20]: np.[TAB]

causes IPython to display all variables in the np module namespace. A search for the string "scalar" will lead you to np.ScalarType and np.isscalar. Typing

In [20]: np.isscalar?

(note the question mark at the end) prompts IPython to show you where np.isscalar is defined:

File:  /data1/unutbu/.virtualenvs/dev/lib/python2.7/site-packages/numpy/core/numeric.py

which is how I got to the definition of isscalar. Alternatively, the NumPy documentation for isscalar has a link to the source code as well.

2 of 4
14

In this context, a scalar is one of the things you put in an array. A single 64-bit float or 32-bit int, for example, rather than a whole array of them.

🌐
IBM
ibm.com › docs › en › netezza
Python language scalar function - IBM
We cannot provide a description for this page right now
🌐
AWS
docs.aws.amazon.com › amazon redshift › database developer guide › user-defined functions in amazon redshift › scalar python udfs
Scalar Python UDFs - Amazon Redshift
A scalar Python UDF incorporates a Python program that runs when the function is called and returns a single value. The command defines the following parameters:
🌐
Apache
nightlies.apache.org › flink › flink-docs-release-1.13 › docs › dev › python › table › udfs › python_udfs
General User-defined Functions | Apache Flink
In order to define a Python scalar function, one can extend the base class ScalarFunction in pyflink.table.udf and implement an evaluation method. The behavior of a Python scalar function is defined by the evaluation method which is named eval.
🌐
Apache Arrow
arrow.apache.org › docs › python › generated › pyarrow.compute.register_scalar_function.html
pyarrow.compute.register_scalar_function — Apache Arrow v23.0.1
A scalar function is a function that executes elementwise operations on arrays or scalars, i.e. a scalar function must be computed row-by-row with no state where each output row is computed only from its corresponding input row. In other words, all argument arrays have the same length, and ...
Find elsewhere
🌐
SciPy
docs.scipy.org › doc › numpy-1.13.0 › reference › arrays.scalars.html
Scalars — NumPy v1.13 Manual
June 10, 2017 - These type descriptors are mostly based on the types available in the C language that CPython is written in, with several additional types compatible with Python’s types. Array scalars have the same attributes and methods as ndarrays.
🌐
Databricks Documentation
docs.databricks.com › developers › user-defined functions (udfs) › python scalar udfs
User-defined scalar functions - Python | Databricks on Google Cloud
February 11, 2026 - This article contains Python user-defined function (UDF) examples. It shows how to register UDFs, how to invoke UDFs, and provides caveats about evaluation order of subexpressions in Spark SQL. In Databricks Runtime 14.0 and below, Python UDFs and Pandas UDFs are not supported on Unity Catalog clusters that use standard access mode. Scalar Python UDFs and Pandas UDFs are supported for all access modes in Databricks Runtime 14.1 and above.
🌐
Dremio
dremio.com › home › wikis › scalar functions
What is Scalar Functions? | Dremio
February 8, 2025 - Can Scalar Functions be used in languages other than SQL? Yes, Scalar Functions can be created and used in various programming languages, including Python, Java, and R.
🌐
IBM
ibm.com › docs › en › netezza
Python language scalar function
We cannot provide a description for this page right now
🌐
Microsoft Learn
learn.microsoft.com › en-us › azure › databricks › udf › python
User-defined scalar functions - Python - Azure Databricks | Microsoft Learn
February 11, 2026 - This article contains Python user-defined function (UDF) examples. It shows how to register UDFs, how to invoke UDFs, and provides caveats about evaluation order of subexpressions in Spark SQL. In Databricks Runtime 12.2 LTS and below, Python UDFs and Pandas UDFs are not supported on Unity Catalog compute that uses standard access mode. Scalar Python UDFs and Pandas UDFs are supported in Databricks Runtime 13.3 LTS and above for all access modes.
🌐
Wellsr
wellsr.com › python › create-scalar-and-aggregate-functions-for-python-sqlite
Create Scalar and Aggregate Functions for Python SQLite - wellsr.com
May 10, 2019 - We can also use a class with a __call__() method as a scalar function. Let’s take a look at a sample class mapping color names to RGB colors: import sqlite3 def test_color_map(): """ Using a Python class as scalar function. """ class ColorMap: """ A class mapping color names into RGB colors.
🌐
Cvxpy
cvxpy.org › tutorial › functions › index.html
Atomic Functions -
For any CVXPY expression expr, the power operator expr**p is equivalent to the function power(expr, p). A scalar function takes one or more scalars, vectors, or matrices as arguments and returns a scalar.
🌐
Ibis
ibis-project.org › reference › scalar-udfs
scalar-udfs – Ibis
Construct a non-vectorized scalar user-defined function that accepts Python scalar values as inputs.
🌐
Scaler
scaler.com › home › topics › python › python functions
Python Functions - Scaler Topics
November 20, 2023 - Example: To call the Function named hello, type the following: ... Learn more about calling a Python function here.
🌐
Quora
quora.com › What-is-difference-between-array-and-scalar-in-Python
What is difference between array and scalar in Python? - Quora
Answer: Briefly, a scalar is one variable - for example an integer. It can take different values at different times, but at any one time it only has one single value. An array is a set of variables - in most languages these all have to be of ...
🌐
Ucdavis
mae.engr.ucdavis.edu › dsouza › Classes › ECS15-W12 › PythonChapter1.pdf pdf
7 Chapter 1: Scalar Variables and Data Types 1. Python as a calculator
Most often, we do not know the exact value of what is in a · particular memory location; rather we know the type of data that is stored there. Python has three main types of variables: - Scalar variables hold the basic building blocks of data: numbers, and characters.