So in addition to what akasaka said (another thumbs up for line profiler from me, great tool) this isn’t a problem with linalg.norm being slow. It’s plenty fast, but calling it thousands of separate times in a Python loop will be slow. This is more just about learning how to vectorize properly. If you’re working in numpy land and you’re calling a numpy function in a loop that’s iterating over more than a handful of items, chances are you’re not vectorizing properly
akasakahakada|2 years ago
If you see a piece of code like this, it rings the bell that the person has no idea what he/she is doing:
Bad Pattern:
Worst Pattern: Perfered: Same applies to all numpy operations.