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.
🌐
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.
🌐
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....
🌐
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 ...
🌐
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
Find elsewhere
🌐
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.
🌐
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:
🌐
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 ...