Ask a Question
Ask Question Login
Corporate Training
  1. Community
  2. Python
  3. Question
Python

How to normalize an array in NumPy?

Asked by Coleman Garvin Apr 14, 2021 1.4K views 1 answer
Share

About this question

Question description - I would like to have the norm of one NumPy array. More specifically, I am looking for an equivalent version of this function

def normalize(v):

norm = np.linalg.norm(v)

if norm == 0:

return v

return v / norm

Is there something like that in sklearn or numpy?

This function works in a situation where v is the 0 vector.

Your answer

1 Answer

More Python discussions

Learn & Explore

Free tutorials and interview questions from industry experts — learn the skill, then get ready to prove it.

Latest Python Blogs

Guides, tips and career advice on Python from JanBask experts.