python - NumPy: how to quickly normalize many vectors? -


How can the list of vectors be naturally normalized in NumPy?

Here is an example that no work:

last operation yield "size mismatch: objects can not be transmitted in a shape."

Vectors How can the generalization of 2D vectors be done beautifully NumPy?

edit : Why does not it work when adding a dimension to criteria (according to my answer)?

Well, unless I miss something, it works:

  vectors / norms  

Your problem suggestion is the broadcast rule.

  vectors # Size 2, 10 criteria # Size 10  

The size does not have the same length! Therefore, the rule is to first extend a small size at left :

  Criteria # Size 1,10  

You can do the same:

  vectors / norms.reshape (1, -1) Similar to # vectors / criteria  

If you want Calculate the vectors.T / Criterion , you must manually reset, as is the following:

  vectors.T / norms.reshape (-1,1) # This works  

Comments