Search code examples
pythonnumpymatplotlibvectormagnitude

Find magnitude of 8D vector using python


I am trying to get output of primary capsule layer in capsule network. According to that I get 1152 number of 8D capsules. Here is one example

[ 0.19123563 -0.11994515 -0.7150253  -0.35917872 -0.02346791 -0.32390958
0.40772104 -0.01656894]

I am finding its magnitude using np.linalg.norm(). Accordingly magnitude is 0.98143137.I don't understand how this is calculated.


Solution

  • The magnitude is the square root of the sum of the squares of all the entries of the vector. The following code would give you the same value: np.sqrt(np.sum(vector**2)). As far as graphing this, I'm unsure of what you are trying to visualize.