Python has powerful built-in types, but Python lists are not mathematical vectors or matrices. You could do this with lists, but it will likely be cumbersome for anything more than trivial operations.

If you find yourself needing vector or matrix arithmetic often, the standard in the field is NumPy, which probably already comes packaged for your operating system the way Python also was.

I share the confusion of others about exactly what it is you're trying to do, but perhaps the numpy.linalg.norm function will help:

>>> import numpy
>>> a = numpy.array([1, 2, 3, 4])
>>> b = numpy.array([2, 3, 4, 5])
>>> numpy.linalg.norm((a - b), ord=1)
4

To show how that's working under the covers:

>>> a
array([1, 2, 3, 4])
>>> b
array([2, 3, 4, 5])
>>> (a - b)
array([-1, -1, -1, -1])
>>> numpy.linalg.norm((a - b))
2.0
>>> numpy.linalg.norm((a - b), ord=1)
4
Answer from bignose on Stack Overflow
🌐
DataCamp
datacamp.com › doc › numpy › linalg-norm
NumPy linalg.norm()
import numpy as np matrix = np.array([[1, -2, 3], [-4, 5, -6]]) norm = np.linalg.norm(matrix, ord=1, axis=0) print(norm) This example uses the `ord` and `axis` parameters to calculate the L1 norm (sum of absolute values) along each column of the matrix.
🌐
Programiz
programiz.com › python-programming › numpy › methods › norm
NumPy norm() (With Examples)
Note: By default, the numpy.linalg.norm() function computes the Frobenius norm for matrices. The L1 norm is a measure of distance or magnitude in vector spaces.
🌐
NumPy
numpy.org › devdocs › reference › generated › numpy.linalg.norm.html
numpy.linalg.norm — NumPy v2.5.dev0 Manual
If axis is an integer, it specifies the axis of x along which to compute the vector norms. If axis is a 2-tuple, it specifies the axes that hold 2-D matrices, and the matrix norms of these matrices are computed. If axis is None then either a vector norm (when x is 1-D) or a matrix norm (when ...
🌐
AskPython
askpython.com › home › how to compute l1 and l2 norms in python?
How to compute L1 and L2 norms in python? - AskPython
February 27, 2023 - The L1 norm is often used in cases where we need a robust solution that is insensitive to outliers, while the L2 norm is often used when we want a solution that is smoother and more predictable. Also read: How to Compute Distance in Python? [ Easy Step-By-Step Guide ] Numpy linear algebra library : https://numpy.org/doc/stable/reference/routines.linalg.html
🌐
Medium
medium.com › @heyamit10 › numpy-norm-fdc8dc604183
What is numpy.linalg.norm and Why is it Useful? | by Hey Amit | Medium
April 18, 2025 - This is where the ord parameter comes in handy. Let me break it down for you: L1 Norm (Manhattan Distance) If you want to sum the absolute values of your vector components (like walking along a grid), use ord=1:
🌐
Sparrow Computing
sparrow.dev › home › blog › numpy norm: understanding np.linalg.norm()
NumPy Norm: Understanding np.linalg.norm() - Sparrow Computing
October 15, 2021 - You can calculate the L1 and L2 norms of a vector or the Frobenius norm of a matrix in NumPy with np.linalg.norm(). This post explains the API and gives a few concrete usage examples.
🌐
KDnuggets
kdnuggets.com › 2023 › 05 › vector-matrix-norms-numpy-linalg-norm.html
Vector and Matrix Norms with NumPy Linalg Norm - KDnuggets
The L1 norm is equal to the sum of the absolute values of elements in the vector: Substituting p =2 in the general Lp norm equation, we get the following expression for the L2 norm of a vector: For a given vector x, the L∞ norm is the maximum ...
Find elsewhere
🌐
Vultr Docs
docs.vultr.com › python › third-party › numpy › linalg › norm
Python Numpy linalg norm() - Calculate Vector Norm | Vultr Docs
November 18, 2024 - The L1 norm sums the absolute values of the components, resulting in 7.0. Prepare a vector to calculate the infinity norm. Specify ord=np.inf within the norm() function to execute this computation.
🌐
EDUCBA
educba.com › home › software development › software development tutorials › numpy tutorial › numpy norm
NumPy norm | Working and examples of NumPy norm
April 3, 2023 - The Vector L1 norm represents the L1 norm of the vector, which calculates the absolute vector values sum. The Vector L2 norm represents the L2 norm of the vector, which calculates the squared vectored values sum and finds its square root.
Address   Unit no. 202, Jay Antariksh Bldg, Makwana Road, Marol, Andheri (East),, 400059, Mumbai
🌐
Analytics Vidhya
analyticsvidhya.com › home › exploring the power of norms with numpy linalg
The Power of Norms with NumPy Linalg | Analytics Vidhya
May 28, 2025 - Let’s explore some of the most commonly used norms in NumPy: The Euclidean norm, or the L2 norm, is perhaps the most well-known norm. It measures a vector’s “length” or “magnitude” using the square root of the sum of squared elements. The Euclidean norm is defined as: ... The Manhattan norm, the L1 norm, calculates a vector’s “length” or “magnitude” by summing its elements’ absolute values.
🌐
SciPy
docs.scipy.org › doc › numpy-1.9.3 › reference › generated › numpy.linalg.norm.html
numpy.linalg.norm — NumPy v1.9 Manual
For values of ord <= 0, the result is, strictly speaking, not a mathematical ‘norm’, but it may still be useful for various numerical purposes. ... >>> from numpy import linalg as LA >>> a = np.arange(9) - 4 >>> a array([-4, -3, -2, -1, 0, 1, 2, 3, 4]) >>> b = a.reshape((3, 3)) >>> b array([[-4, -3, -2], [-1, 0, 1], [ 2, 3, 4]])
🌐
OpenGenus
iq.opengenus.org › norm-method-of-numpy-in-python
.norm() method of Numpy library in Python
June 3, 2020 - Then the L1 norm can be calculated by, where |x| is the magnitude of x. Mathematically, it's same as calculating the Manhattan distance of the vector from the origin of the vector space.
🌐
Hadrienj
hadrienj.github.io › posts › Deep-Learning-Book-Series-2.5-Norms
Introduction to Norms using Python/Numpy examples and drawings
March 26, 2018 - Go and plot these norms if you need to move them in order to catch their shape. It is the $L^\infty$ norm and corresponds to the absolute value of the greatest element of the vector.
🌐
Medium
koshurai.medium.com › demystifying-l1-norm-and-l2-norm-in-python-your-guide-to-understanding-and-implementing-6390ee0ae8fe
Demystifying L1 Norm and L2 Norm in Python: Your Guide to Understanding and Implementing | by KoshurAI | Medium
February 25, 2024 - In this code snippet, we use NumPy’s linalg.norm() function to compute the norms of our vector. The ord parameter specifies the type of norm we want to calculate: ord=1 for L1 norm and ord=2 for L2 norm.
🌐
SciPy
docs.scipy.org › doc › scipy › reference › generated › scipy.linalg.norm.html
norm — SciPy v1.17.0 Manual
Both the Frobenius and nuclear norm orders are only defined for matrices. ... G. H. Golub and C. F. Van Loan, Matrix Computations, Baltimore, MD, Johns Hopkins University Press, 1985, pg. 15 ... Try it in your browser! >>> import numpy as np >>> from scipy.linalg import norm >>> a = np.arange(9) - 4.0 >>> a array([-4., -3., -2., -1., 0., 1., 2., 3., 4.]) >>> b = a.reshape((3, 3)) >>> b array([[-4., -3., -2.], [-1., 0., 1.], [ 2., 3., 4.]])
🌐
Medium
medium.com › @whyamit101 › understanding-vector-norm-in-numpy-230af2a4461c
Understanding Vector Norm in NumPy | by why amit | Medium
February 26, 2025 - Notice how we take the absolute values and sum them up? That’s the L1 norm in action!