60 points · by Tomte · 3y ago · 24 comments
https://twitter.com/jeremyphoward/status/1575312671288991744
from numpy.random import randn
randn(3,1,7,5) - randn(1,4,1,5)
Inspired by other comments in this thread: The second line can also be run in current versions of Octave/Matlab as-is, BUT they didn't support it before NumPy, and neither did/does FORTRAN[2]. Mathworks resisted introducing this general form of broadcasting into Matlab for a long time. Octave then did it anyway (version 3.6.0 in 2012), and Matlab eventually followed (version R2016b). Before late 2016, Matlab code required `bsxfun(@minus, A, B)` instead of `A-B` to get broadcasting, and before bsxfun (introduced in R2007a) it was even more awkward (code often used `repmat`, or indexing tricks to explicitly expand arrays in memory to match shape).[1] https://aplwiki.com/wiki/Conformability
[2] suggestion from 2022 to introduce broadcasting to Fortran: https://github.com/j3-fortran/fortran_proposals/issues/252
> a friend had written some code in—either numpy, or something else borrowing its model—and wanted to translate it to j. I could not figure out what she was trying to accomplish with the many seemingly-extraneous reshapes and transposes, until I found out what they did in numpy. The whole thing reduced to a single, trivial application of rank in j
[0] https://aplwiki.com/wiki/APL_Farm, main or "Array languages" channel
real a(32,32)
real b(32)
b = a(:,4)ALGOL 68 had some form of array slicing as well, but I'm not sure how influential it really was in this department.
For fiber optics simulations in science applications.
…anyone with stories from the road?
Cam mechanisms, and other stuff that I can't find the English words for right now :)
I've forgotten everything about it, but I remember that it had quite "magical" array indexing. I haven't encountered another language that comes even close to that.