Ask HN: How did Python become the lingua franca of ML/AI?
Because Python has NumPy, which implements vectorized math on arrays and matrices.  Machine learning algorithms are implemented naturally and efficiently with those primitives.  PyTorch, TensorFlow, and I think every other machine learning framework in Python all use NumPy.<p>JavaScript, Ruby, and Perl either don&#x27;t have this abstraction at all, or they have much weaker versions of it, and many fewer scientific libraries.<p>NumPy started in the early 2000&#x27;s and continues to this day.  It takes decades to build up this infrastructure!  This recent interview with NumPy creator Travis Oliphant is great:<p><a href="https:&#x2F;&#x2F;www.youtube.com&#x2F;watch?v=gFEE3w7F0ww" rel="nofollow">https:&#x2F;&#x2F;www.youtube.com&#x2F;watch?v=gFEE3w7F0ww</a><p>He talks about how there were competing abstractions like &quot;Numeric&quot; and another library, and his goal with NumPy was to unify them.  And how there are still some open design issues &#x2F; regrets.<p>There were multiple people in the nascent Python community who were tired of MATLAB, not just because it&#x27;s proprietary, but because it&#x27;s a weak and inefficient language for anything other than its scientific use cases.  You won&#x27;t have a good time trying to write a web app wrapper in MATLAB, for example.<p>The much more recent Julia language is also inspired positively and negatively by MATLAB, and is very suitable for machine learning, though it doesn&#x27;t have the decades of libraries that Python has.<p>-----<p>The NumPy extension was in turn enabled by operator overloading in Python (which is actually a very C++ influenced mechanism).  JavaScript doesn&#x27;t have operator overloading; I&#x27;m pretty sure Perl doesn&#x27;t, but not sure about Ruby.  Lua and Tcl do not have it.  (Lua does have a machine learning framework though -- <a href="http:&#x2F;&#x2F;torch.ch&#x2F;" rel="nofollow">http:&#x2F;&#x2F;torch.ch&#x2F;</a> -- but I think PyTorch is more popular now.)<p>So if Guido didn&#x27;t design Python with operator overloading, then NumPy would not have grown out of it.<p>Also relevant is Guy Steele&#x27;s famous talk <i>Growing a Language</i> (late 90&#x27;s or early 2000&#x27;s I think).  He advocates for operator overloading in Java so end users can evolve language with their domain expertise!  Well Java never got it, and Python ended up having the capabilities to grow linear algebra.<p>Guido has even said he doesn&#x27;t really use or even &quot;get&quot; NumPy!  So it turns out that an extensible design does have the benefits that Steele suggested (although it&#x27;s a very difficult language design problem.)  There have been several enhancements to Python driven by the NumPy community, like slicing syntax and semantics and the @ matrix multiplication operator.  And I think many parts of the C API like buffers.<p>-----<p>Another interesting thing from Oliphant&#x27;s interview is that he really liked that Python has complex numbers.  (I don&#x27;t think any of JavaScript, Ruby, Perl, or Lua have them in the core, which is important.)  That piqued his interest and kicked off a few decades of hacking on Python.<p>He was an electrical engineering Ph.D. student and professor, and complex numbers are ubiquitous in that domain.  Example:<p><pre><code>    $ python3 -c &#x27;print(3j * 2 + 1)&#x27;
    (1+6j)

</code></pre>
This is another simple type built on Python&#x27;s extensible core, and it&#x27;s short.<p><pre><code>    $ Python-3.9.4$ wc -l Objects&#x2F;complexobject.c 
    1125 Objects&#x2F;complexobject.c

</code></pre>
I recommend writing a Python extension in C if you want to see how it works.  See Modules&#x2F;xx*.c in the Python source code for some templates &#x2F; examples.  IMO the Python source code is a lot more approachable than Perl, Ruby, or any JS engine I&#x27;ve looked at.