A single value represents the most fundamental piece of information in data. This is termed a scalar in linear algebra. Consider a scalar as an ordinary number. It has magnitude but no direction. It is the simplest possible data element for computation.
For example, when we measure the temperature of a room, we get a single number, like 21°C. When we check the price of an item, we see a single value, such as $49.95. These individual numbers are scalars.
In machine learning, scalars appear everywhere. They are often used to represent specific, singular quantities:
Mathematically, scalars are typically written as lowercase, italicized letters, such as c, k, or x. You might also see them represented by Greek letters, like α (alpha) or λ (lambda). For example, we could define a scalar s as:
s=5A scalar doesn't need any special structure to hold it; it's just a value on its own.
A scalar is a single numerical quantity. It is the basic building block for more complex data structures.
In Python, a scalar is represented by the standard numerical data types you are likely already familiar with: int for integers and float for floating-point (decimal) numbers. There's no special "scalar" object.
Here’s how you would define a few scalars in Python:
# An integer scalar
sample_count = 150
# A floating-point scalar
learning_rate = 0.001
# Another scalar representing a model parameter
bias_term = -2.5
print(f"Sample count: {sample_count} (Type: {type(sample_count)})")
print(f"Learning rate: {learning_rate} (Type: {type(learning_rate)})")
The output confirms that these are just regular Python numbers:
Sample count: 150 (Type: <class 'int'>)
Learning rate: 0.001 (Type: <class 'float'>)
Although simple, understanding scalars is the first step. They are the atoms that we will use to construct vectors and matrices, which are essential for representing collections of data and entire datasets. Next, we will see how we can group these scalars together to form vectors.
Was this section helpful?
© 2026 ApX Machine LearningEngineered with