NumPy: The tricks of the trade (Part II)
This post will describe about the more advanced and fun stuff about NumPy. For basics, refer to Part I. Vectorization First let’s revisit how we would do any arithmetic operation on all the elements of list (Python in-built container). Looping through all the elements is probably the only way to go about it. The neatest syntax is using list comprehensions. # List Comprehension >>> L = [1,2,3,4] >>> [i * 2 for i in L] # list comprehension [2, 4, 6, 8] Now imagine doing this for a multi-dimensional list of data and think about the readability....