3 ms·
I wish the "Iverson bracket" (number 0 in this list) had caught on in a bigger way. It can really simplify writing conditional expressions, as opposed to e.g. a
by Y_Y 7y ago
I wish the "Iverson bracket" (number 0 in this list) had caught on in a bigger way. It can really simplify writing conditional expressions, as opposed to e.g. a case expression.
- david_draco 7y agoYou can do that easily in numpy. ((x>0)-(x<0))*1 will give zeros and ones.
- contravariant 7y agoIt's also an exceptionally useful technique in mathematics if you've got a few nested sums with dependend indices. By writing the condition in an Iverson bracket it becomes trivial to change the order of summation or change one of the variables.
- dubya 7y agoI don't know if Knuth popularized it, but it's somewhat common in combinatorics. Similar idea to using indicator functions when doing change of variables in calculus. https://arxiv.org/abs/math/9205211 https://arxiv.org/abs/math/9205211