For more information about concepts covered in this lesson, you can check out:
The NumPy Module vs the math Module
00:13 If you’re working with arrays of numerical values, then you definitely want to check out the NumPy module. The NumPy module offers comprehensive mathematical functions, random number generators, linear algebra routines, Fourier transform functions, and just in general, a plethora of functions to work with arrays of numerical values.
The main advantage of NumPy versus
math is that math operations in NumPy are optimized to work with NumPy arrays, or ndarrays. All looping in NumPy is done using optimized C functions, which is another reason why you may want to use NumPy if you’re working with arrays of numerical values instead of creating your own functions that are written in Python and using basic
One nice feature with NumPy is that many of the functions that we talked about—like the exponential function, sine and cosine, the natural logarithm—they can be applied directly to NumPy arrays, and therefore return NumPy arrays that you can then work with. However, if you plan on working mostly with scalar values, then you may just want to stick with the
math module functions.
01:31 These can be faster than their NumPy equivalents, and the reason is because the NumPy functions, they’re going to convert the values that are passed in as inputs into arrays, and so this will slow down the computation if you plan on doing many computations with these functions.
Now, we can’t really go even into the basics of NumPy in this video course on the
math module, so instead, I’ll refer you to a realpython.com tutorial on NumPy called Your First Steps Into Data Science in Python.
Become a Member to join the conversation.