You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Here is an optimized version of your program. The major performance gain comes from using more efficient built-in functions and avoiding unnecessary computation inside the loop.
Key points.
- Instead of creating a list using a list comprehension, use list multiplication, as `total % self.num_classes` is a constant for all elements.
- `sum(features)` is already efficient, but now it is only called once, and the modulo operation is also computed just once.
Optimized code.
This eliminates redundant computation inside the loop, resulting in a much faster classification, especially for large feature vectors.
0 commit comments