SI
SI
discoversearch

We've detected that you're using an ad content blocking browser plug-in or feature. Ads provide a critical source of revenue to the continued operation of Silicon Investor.  We ask that you disable ad blocking while on Silicon Investor in the best interests of our community.  If you are not using an ad blocker but are still receiving this message, make sure your browser's tracking protection is set to the 'standard' level.
Strategies & Market Trends : Technical analysis for shorts & longs -- Ignore unavailable to you. Want to Upgrade?


To: Johnny Canuck who wrote (70678)2/11/2026 3:29:01 PM
From: Johnny Canuck  Respond to of 70697
 
<OT>

The limitaion of this approach is it assume you know the nature or properties on the input for each anticipated iteration. That is not always possible.

>>>>>>>>>>>>>>>>>>>>>>

Gemini said

This video explains why using traditional Python for-loops for numerical data can make your code up to 100 times slower than it needs to be and introduces vectorization with NumPy as the superior alternative.

The Problem with For-Loops
  • Inefficiency: Python for-loops are slow because they perform "type checking" at every iteration, jump between memory locations constantly, and execute instructions one by one [ 01:01].

  • The Warehouse Analogy: Using a for-loop is like moving 10,000 boxes across a warehouse by carrying one at a time. In contrast, vectorization is like using a forklift to move everything at once [ 00:32].

The Power of NumPy Vectorization
  • Compiled Speed: When you use NumPy, the heavy lifting is handed off to optimized, compiled C code under the hood, which runs at near-hardware speeds [ 01:10].

  • Code Comparison: The video demonstrates summing 10 million numbers. While a standard Python loop manually iterates through the array, the NumPy version accomplishes the same task in a single line of code [ 01:25].

  • Result: Both methods produce the same outcome, but the vectorized version is dramatically faster because Python is no longer "in charge" of the individual operations [ 01:45].

Real-World Impact
  • AI and Machine Learning: Infields like AI, data is massive. Inefficient pre-processing loops can slow down a model before training even begins, and no optimizer can fix bad fundamentals [ 02:11].

  • The Golden Rule: If you are looping over numbers in Python, there is almost always a vectorized NumPy way to do it. Loops describe how to do something, whereas vectorization lets the machine decide the fastest way to execute the task [ 02:33].

You can watch the full video here: youtube.com



Stop Writing For-Loops. (Your Python is 100x slower than it should be.)

Tabish Khaqan · 9 views