All 3D vectors can be represented by a directed line segment in 3D space R 3, which has a start point and an end point. This gives each vector a magnitude (the length of the line segment) and direction (from the start point to the end point). They have a rigorous definition in. If 'r' is a vector. Norm(r), gives the magnitude only if the vector has values. If r is an array of vectors, then the norm does not return the magnitude, rather the norm!!
![Magnitude Magnitude](/uploads/1/2/5/4/125498746/314147382.jpg)
If you are worried at all about speed, you should instead use: mag = np.sqrt(x.dot(x))Here are some benchmarks: import timeit timeit.timeit('np.linalg.norm(x)', setup='import numpy as np; x = np.arange(100)', number=1000)0.0450878 timeit.timeit('np.sqrt(x.dot(x))', setup='import numpy as np; x = np.arange(100)', number=1000)0.0181372EDIT: The real speed improvement comes when you have to take the norm of many vectors. Using pure numpy functions doesn't require any for loops. For example: In 1: import numpy as npIn 2: a = np.arange(1200.0).reshape((-1,3))In 3:%timeit np.linalg.norm(x) for x in a100 loops, best of 3: 4.23 ms per loopIn 4:%timeit np.sqrt((a.a).sum(axis=1))100000 loops, best of 3: 18.9 us per loopIn 5: np.allclose(np.linalg.norm(x) for x in a,np.sqrt((a.a).sum(axis=1)))Out5: True. Fastest way I found is via inner1d.
![Calculator Calculator](/uploads/1/2/5/4/125498746/175251181.png)
You've told us this page needs code samples. If you'd like to help us further, you could provide a code sample, or tell us about what kind of code sample you'd like to see:You've told us there are code samples on this page which don't work. If you know how to fix it, or have something better we could use instead, please let us know:You've told us there is information missing from this page. Please tell us more about what's missing:You've told us there is incorrect information on this page.
If you know what we should change to make it correct, please tell us:You've told us this page has unclear or confusing information. Please tell us more about what you found unclear or confusing, or let us know how we could make it clearer:You've told us there is a spelling or grammar error on this page. Please tell us what's wrong:You've told us this page has a problem. Please tell us more about what's wrong.