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.
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
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
How should I initialize a numpy array of NaN values?
>>> np.full(3, np.nan) But the bigger question is why would you want to? Edit: as an explanation, your example does not work because you initialized an array of ints. ints have no "NaN" value, only floats do. So your method would work if you initialized an array of floats: >>> x = np.array([0.0,0.0,0.0]) >>> x.fill(np.nan) >>> x array([ nan, nan, nan]) Or converted the ints to floats: >>> x = np.array([0,0,0], dtype=np.float) >>> x.fill(np.nan) >>> x array([ nan, nan, nan]) But the np.full() method is much better. More on reddit.com
🌐 r/learnpython
5
5
April 8, 2016
🌐
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.
🌐
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 - The magnitude or length of a vector is a measure of its size. This metric is commonly referred to as the Euclidean norm of a vector, but there are other norms, each suited to different applications.
🌐
NumPy
numpy.org › doc › 2.1 › reference › generated › numpy.ndarray.size.html
numpy.ndarray.size — NumPy v2.1 Manual
Number of elements in the array · Equal to np.prod(a.shape), i.e., the product of the array’s dimensions
🌐
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 - # Importing the NumPy library and aliasing it as 'np' import numpy as np # Creating a NumPy array 'x' containing integers x = np.array([1, 2, 3, 4, 5]) # Printing a message indicating the original array will be displayed print("Original array:") # Printing the original array 'x' with its elements print(x) # Printing a message indicating the calculation of the magnitude of the vector print("Magnitude of the vector:") # Calculating the magnitude (L2 norm) of the vector 'x' using np.linalg.norm() function magnitude = np.linalg.norm(x) # Printing the calculated magnitude of the vector 'x' print(ma
🌐
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 ...
Find elsewhere
🌐
Codegive
codegive.com › blog › numpy_length_of_vector.php
Numpy length of vector
For example, a 2D vector v = [x, ... irrespective of its direction. When working with NumPy arrays, a very common mistake for beginners is to use the built-in len() function to find the vector's mathematical length....
🌐
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.
🌐
Codegive
codegive.com › blog › python_numpy_length_of_vector.php
Python numpy length of vector
It's the scalar value representing the geometric length of the vector. Number of Elements: The total count of items in the array (e.g., 3 elements in [1, 2, 3]). Number of Dimensions: How many axes the array has (e.g., a 1D array is a vector, a 2D array is a matrix).
🌐
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
NumPy is the ideal choice for these operations due to its performance and simplicity, specifically designed for numerical computing tasks. ... L_2L2​) measures the "straight-line" distance from the origin to the point represented by the vector, effectively the length of the vector.
🌐
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 - You can use the shape attribute of a NumPy array to get its dimensions. For a 1D array, it gives the length of the array.
🌐
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.
🌐
w3resource
w3resource.com › python-exercises › numpy › basic › numpy-basic-exercise-23.php
NumPy: Create a vector of length 5 filled with arbitrary integers from 0 to 10 - w3resource
August 28, 2025 - NumPy Basic Exercises, Practice and Solution: Write a NumPy program to create a vector of length 5 filled with arbitrary integers from 0 to 10.
🌐
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.
🌐
IncludeHelp
includehelp.com › python › how-do-you-get-the-magnitude-of-a-vector-in-numpy.aspx
Python - How do you get the magnitude of a vector in NumPy?
October 7, 2023 - Numpy arrays can also be used to depict a vector. To get the magnitude of a vector in NumPy, we can either define a function that computes the magnitude of a given vector based on a formula or we can use the norm() method in linalg module of NumPy.
🌐
NumPy
numpy.org › doc › stable › reference › generated › numpy.ndarray.size.html
numpy.ndarray.size — NumPy v2.4 Manual
Number of elements in the array · Equal to np.prod(a.shape), i.e., the product of the array’s dimensions
🌐
Statology
statology.org › home › how to calculate the magnitude of a vector using numpy
How to Calculate the Magnitude of a Vector Using NumPy
September 17, 2021 - The magnitude of the vector is 21.77. Notice that this matches the value that we calculated using the previous method. The following tutorials explain how to perform other common operations using NumPy: