Vector Spaces
Yeshwanth Nagaraj
Democratizing Math and Core AI // Levelling playfield for the future
In mathematics, a vector space, also known as a linear space, is a mathematical structure that consists of a set of vectors along with operations of vector addition and scalar multiplication. Vector spaces are fundamental in linear algebra and have wide applications in various areas of mathematics, physics, computer science, and engineering.
Here are the key properties and characteristics of vector spaces:
These properties ensure that vector spaces are well-behaved and have consistent algebraic structures. Examples of vector spaces include Euclidean spaces (such as 2D and 3D Cartesian spaces), function spaces, polynomial spaces, and more.
领英推荐
class Vector:
? ? def __init__(self, values):
? ? ? ? self.values = values
? ? def __add__(self, other):
? ? ? ? if isinstance(other, Vector) and len(self.values) == len(other.values):
? ? ? ? ? ? new_values = [x + y for x, y in zip(self.values, other.values)]
? ? ? ? ? ? return Vector(new_values)
? ? ? ? else:
? ? ? ? ? ? raise ValueError("Vector addition is only defined for vectors of the same length.")
? ? def __mul__(self, scalar):
? ? ? ? if isinstance(scalar, (int, float)):
? ? ? ? ? ? new_values = [scalar * x for x in self.values]
? ? ? ? ? ? return Vector(new_values)
? ? ? ? else:
? ? ? ? ? ? raise ValueError("Scalar multiplication is only defined for numeric scalars.")
? ? def __str__(self):
? ? ? ? return str(self.values)
# Example usage
v1 = Vector([1, 2, 3])
v2 = Vector([4, 5, 6])
# Vector addition
v3 = v1 + v2
print("Vector addition:", v3)
# Scalar multiplication
scalar = 2
v4 = v1 * scalar
print("Scalar multiplication:", v4)