<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">"""Module for vector and matrix operations.

Vectors are represented by lists.

For example,
    x = [3, 6]  # define a 2-d vector

Matrices are represented by lists of lists, where each row corresponds to an inner list.
    A = [[3,6], [1,2]]  # define a 2x2 matrix

    a[1][1]  # -&gt; 2 access the second row, second column element

This module supports any dimensional vectors.
"""
from typing import List

def add_vectors(vector_1: List[float], vector_2: List[float]) -&gt; List[float]:
    """Compute the sum of two vectors.

    The two vectors are expected to have the same length.

    :param vector_1: The first vector.
    :param vector_2: The second vector.
    :return: The sum of the two vectors.
    """
    sum_vector = []
    for i in range(0, len(vector_1)):
        sum_vector.append( vector_1[i] + vector_2[i] )

    # for x, y in zip(vector_1, vector_2):
    #     sum_vector.append(x+y)

    return sum_vector

def scalar_product(vector_1: List[float], vector_2: List[float]) -&gt; float:
    """Compute the scalar product of two vectors.

    :param vector_1: The first vector.
    :param vector_2: The second vector.
    :return: The scalar product of the two vectors.
    """
    sum = 0
    for i in range(0, len(vector_1)):
        sum += vector_1[i] * vector_2[i]
    return sum

def matrix_vector_multiplication(matrix: List[List[float]], vector: List[float]) -&gt; List[float]:
    """Compute the product Ax of a matrix A and a vector x

    :param vector_1: The matrix A.
    :param vector_2: The vector x.
    :return: The vector computed by multiplying the matrix A with the vector x.
    """
    # result_vector = []
    # for i in range(0, len(matrix)):
    #     result_vector.append( scalar_product(matrix[i], vector) )

    result_vector = []
    for row in matrix:
        result_vector.append(scalar_product(row, vector))

    return result_vector

x_1 = [1, 2, 3]
x_2 = [3, 5, 3]

mat = [[1, 0, 1], [0, 1, 3], [3,3,1]]

print( add_vectors(x_1, x_2) )
print( scalar_product(x_1, x_2) )
print( matrix_vector_multiplication(mat, x_1) )</pre></body></html>