4 ms·
With numpy, this would just be item.foo [:] = bar. Much more readable to me - the whole «for» thing is superfluous.
by pletnes 5y ago
With numpy, this would just be item.foo [:] = bar. Much more readable to me - the whole «for» thing is superfluous.
- maest 5y agoNeat trick. Didn't know about it. In pandas it would be item.foo = bar, _as long as_ bar isn't something you can iterate over.
- pletnes 5y agoNumpy is all about this. E.g y = np.sin(x). X and y are arrays and you can think of them as «all values of x and y» or «the physical variables x and y»
- jbluepolarbear 5y agoThese comments from people who don’t write software and only use programming for data science. Numpy is superfluous for anyone that doesn’t need it.
- kergonath 5y agoIndeed. Also, this notation was lifted straight from Fortran 90 (which itself got it from Matlab, Algol, and the primitive slicing that was possible in older FORTRANs). The idea that a concise notation is helpful for the concept of “put a thing in all the buckets of an array” really is quite old. It does make a lot of sense.