The function you're after is numpy.linalg.norm. (I reckon it should be in base numpy as a property of an array -- say x.norm() -- but oh well).

import numpy as np
x = np.array([1,2,3,4,5])
np.linalg.norm(x)

You can also feed in an optional ord for the nth order norm you want. Say you wanted the 1-norm:

np.linalg.norm(x,ord=1)

And so on.

Answer from mathematical.coffee on Stack Overflow
🌐
Medium
medium.com › @whyamit101 › understanding-vector-length-in-numpy-c05264f58ef2
Understanding Vector Length in NumPy | by why amit | Medium
February 26, 2025 - Lengths of Vectors: [ 5. 2.23606798 13. ] ... And just like that, NumPy handles multiple vectors with ease.
🌐
Medium
medium.com › @amit25173 › understanding-vector-length-in-numpy-5d84d67abb30
Understanding Vector Length in NumPy | by Amit Yadav | Medium
February 8, 2025 - The most common way to find the length of a vector is using the Euclidean norm, also known as the L2 norm. Here’s how it works: ... Let’s see this in action with a simple example.
Discussions

Vector angles with numpy
There's two issues: If both X and Y are shape (n, m), np.inner(X, Y) will return a shape (n, n) array containing the inner product for each possible combination of vector from X and Y. In general, for batched operations, it's better to stay away from the standard linear algebra functions like inner, dot, matmul, etc., which all behave kind of weirdly for higher-dimensional inputs, and instead implement them manually or by using np.einsum, that makes it a lot more consistent. Batched inner product can be implemented using an element-wise multiplication followed by a sum-reduction of the second axis: inner = np.sum(X*Y, axis=1) You're missing the conversion to degree at the end (NumPy and in fact most libraries/languages operate with radians by default). You can use the function np.rad2deg for that. Clipping the cosine to between -1 and 1 should be redundant. Edit: Actually, there's a third, since there's a similar problem with np.linalg.norm. You need to specify axis=1, otherwise it calculates the norm by treating the entire flattened array as one large vector: x_u = np.linalg.norm(X, axis=1) y_u = np.linalg.norm(Y, axis=1) More on reddit.com
🌐 r/learnpython
3
1
February 11, 2022
Numpy array of part of a vector
Your slice notation is off (also I'm not sure what's the type of your vector, is it a numpy array, or a regular list?). You get a slice from the 3rd element (inclusive) to the 2nd to last (exclusive) using: vector[2:-2] If vector is a list, you need to pass the above to numpy.array() to create a numpy array: arr = numpy.array(vector[2:-2]) If vector is a numpy array itself, the result of vector[2:-2] will also be an array, so you wouldn't need to do anything else. More on reddit.com
🌐 r/learnpython
2
1
November 8, 2021
Struggled with Vector Magnitude? Here’s the Easiest Way I Found to Understand It (with visuals + NumPy)
Your blog post was a good read, especially the question regarding 3d Vector, it helped me internalize the text that I had just read. Keep up the good work👍 More on reddit.com
🌐 r/learnmachinelearning
3
2
August 1, 2025
Find the length of a vector (Vector3D?)
An manim Vector3D is just a numpy NDArray. You could import numpy and use its linalg functions to get the norm. Or you could make use of the per-element multiplication to make your own length function: def vec_norm(vec): return math.sqrt((vec*vec).sum()) More on reddit.com
🌐 r/manim
2
1
May 23, 2024
🌐
Codegive
codegive.com › blog › numpy_length_of_vector.php
Numpy length of vector
Using len(vec): 2 As you can see, len(vec) gives 2, because there are two elements in the array. This is not the mathematical length of 5. So, len() is not what we want for vector magnitude. Let's implement the formula directly using NumPy's array operations.
🌐
Statology
statology.org › home › how to calculate the length or magnitude of a vector in python
How to Calculate the Length or Magnitude of a Vector in Python
July 1, 2024 - This metric is commonly referred to as the Euclidean norm of a vector, but there are other norms, each suited to different applications. Here is how you can calculate the Euclidean norm of a vector using Python: import numpy as np # ...
🌐
pythontutorials
pythontutorials.net › blog › numpy-length-of-vector
Understanding the Numpy Length of a Vector — pythontutorials.net
In NumPy, a vector is represented as a 1D array. The number of elements in a vector is simply the size of the array. This can be thought of as the length in terms of the number of components in the vector.
🌐
pythontutorials
pythontutorials.net › blog › numpy-vector-length
Understanding and Calculating Numpy Vector Length — pythontutorials.net
In a geometric sense, a vector is an object that has both magnitude (length) and direction. In NumPy, a vector is represented as a one - dimensional array. The length of a vector, also known as its magnitude, is calculated using the Euclidean norm.
Find elsewhere
🌐
CodeRivers
coderivers.org › blog › python-length-of-vector
Python Length of Vector: A Comprehensive Guide - CodeRivers
February 22, 2026 - In this example, the len() function returns the integer value 5, which is the number of elements in the vector_list. NumPy arrays have a size attribute that can be used to determine the number of elements in the array.
🌐
CodeSignal
codesignal.com › learn › courses › fundamentals-of-vectors-and-matrices-with-numpy › lessons › vector-properties-and-norms-with-numpy
Vector Properties and Norms with NumPy
L_2L2​) measures the "straight-line" distance from the origin to the point represented by the vector, effectively the length of the vector. ... import numpy as np # Defining a vector vector = np.array([3, 4, 5]) # Calculating the Euclidean Norm magnitude = np.linalg.norm(vector) # Display ...
🌐
APXML
apxml.com › courses › linear-algebra-essentials-ml › chapter-1-vectors-in-machine-learning › implementing-vector-operations-numpy
Implementing Vector Operations with NumPy
The default for np.linalg.norm ... as the norm of their difference, ... ||a - b||∣∣a−b∣∣. Using NumPy, this is a combination of subtraction and the norm function....
🌐
GeeksforGeeks
geeksforgeeks.org › python › how-to-get-the-magnitude-of-a-vector-in-numpy
How to get the magnitude of a vector in NumPy? - GeeksforGeeks
August 18, 2022 - The fundamental feature of linear algebra are vectors, these are the objects having both direction and magnitude. In Python, NumPy arrays can be used to depict a vector.
🌐
Codingtag
codingtag.com › how-to-get-the-magnitude-of-a-vector-in-numpy
How to get the magnitude of a vector in NumPy?
This is commonly done using the numpy.linalg.norm() function, which calculates the Euclidean norm (or L2 norm) of a vector. It provides a reliable and efficient way to determine the length or size of a vector in scientific and engineering ...
🌐
Note.nkmk.me
note.nkmk.me › home › python › numpy
NumPy: Get the dimensions, shape, and size of an array | note.nkmk.me
April 23, 2025 - You can get the number of dimensions, the shape (length of each dimension), and the size (total number of elements) of a NumPy array (numpy.ndarray) using the ndim, shape, and size attributes. The bui ...
🌐
Spark By {Examples}
sparkbyexamples.com › home › python › how to get numpy array length
How to Get NumPy Array Length - Spark By {Examples}
March 27, 2024 - In Python Numpy you can get array length/size using numpy.ndarray.size and numpy.ndarray.shape properties. The size property gets the total number of
🌐
Pierian Training
pieriantraining.com › home › python numpy tutorial: get length of array in python
Python NumPy Tutorial: Get Length of Array in Python - Pierian Training
April 27, 2023 - The easiest and most straightforward way to get the length of a NumPy array is by using the built-in Python function `len()`. This function returns the number of elements in an object, including the elements in a NumPy array.
🌐
W3Schools
w3schools.com › python › gloss_python_array_length.asp
Python Array Length
Use the len() method to return the length of an array (the number of elements in an array).
🌐
NumPy
numpy.org › doc › 2.1 › reference › generated › numpy.linalg.norm.html
numpy.linalg.norm — NumPy v2.1 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 x is 2-D) is returned.
🌐
w3resource
w3resource.com › python-exercises › numpy › python-numpy-exercise-93.php
NumPy: Get the magnitude of a vector in NumPy - w3resource
August 29, 2025 - NumPy Array Object Exercises, Practice and Solution: Write a NumPy program to get the magnitude of a vector in NumPy.