3 ms·
If ages is a numpy array instead of a list: (ages > 17).sum()
by adalacelove 3y ago
If ages is a numpy array instead of a list:
(ages > 17).sum()
- dTal 3y agoNumpy is something close to APL semantics with Python syntax. There's no doubt it was heavily inspired by APL. One could argue that numpy's popularity vindicates the array model pioneered by APL, while driving a nail in the coffin of "notation as a tool of thought", or APL's version of it at any rate. Array programming has never been more popular but there's no demand for APL syntax.
- adalacelove 3y agoI think the key to array programming success was due to the possibility of having fast interpreted languages for numerical computing. I'm very used to programming in array languages (Matlab, Python, Julia and even Mathematica has lot of vectorized ops) and still I think a lot in terms of for loops.
- sideshowb 3y agoThis. Ideally we'd have jitted python loops be efficient. I love array syntax for simple examples but for more complex ops a loop is often clearer.
- TheRealKing 3y agoNumpy's vectorized syntax is inspired by Fortran.