NumPy has many universal functions (so-called ufuncs), so use them to your advantage to eliminate as many loops as you can to optimize your code. The ufuncs have a pretty good coverage in math, trigonometry, summary statistics, and comparison operations. For detailed ufunc lists, refer to the online documentation at http://docs.scipy.org/doc/numpy/reference/ufuncs.html .
Due to the large amount of ufuncs in NumPy, we can hardy cover all of them in a chapter. In this section, we only aim to understand how and why NumPy ufuncs should be used.
Most ufuncs are either unary or binary, which means that they can take only one or two arguments and apply them, element-wise or in mathematics; this is referred to as a vectorized operation or a NumPy arithmetic operation, which we explained in previous sections. Here are some common ufuncs:
In [21]: x = np.arange(5,10) In [22]: np.square(x) Out[22]: array([25, 36, 49, 64, 81]) ...