python-scipyHow do I calculate the norm of a numpy array in Python?
The norm of a numpy array is the length of the array, which can be calculated using the numpy.linalg.norm()
function.
import numpy as np
arr = np.array([1, 2, 3])
norm = np.linalg.norm(arr)
print(norm)
Output example
3.7416573867739413
The code above:
import numpy as np
: imports the numpy library into the scriptarr = np.array([1, 2, 3])
: creates a numpy array from the list of numbersnorm = np.linalg.norm(arr)
: calculates the norm of the numpy arrayprint(norm)
: prints the result
Helpful links
More of Python Scipy
- How do I use Python Scipy to perform a Z test?
- How do I calculate the cross-correlation of two arrays using Python and NumPy?
- How can I check if a certain version of Python is compatible with SciPy?
- How do I use Python Numpy to read and write Excel (.xlsx) files?
- How do I use the trapz function in Python SciPy?
- How do I create a 2D array of zeros using Python and NumPy?
- How can I use Python and SciPy to find the zeros of a function?
- How can I use Python Scipy to zoom in on an image?
- How do I use Python XlsxWriter to write a NumPy array to an Excel file?
- How do I use Python and SciPy to write a WAV file?
See more codes...