I have a list L that is full of vectors, I want to calculate the norm of each of these vectors And add the values to a new list N.
I did the following (problem is it returns a single value.. instead of a list of values with all the different norms ) what should i add?
N = list()
from numpy import linalg as LA
N.append(LA.linalg.norm(L,ord=None))
print(N)
Your current code LA.linalg.norm(L,ord=None)
calculates a single norm value for the entire list of vectors. To calculate separate norms for each vector in your L
list, you should loop over that list and append each result to the N
list, eg,
N = list()
from numpy import linalg as LA
for vector in L:
N.append(LA.linalg.norm(vector,ord=None))
print(N)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.