Python: Numpy Part II

Beyond numpy’s usefulness in creating arrays and matrices, numpy also provides a great suite of math functions that – for anyone with any programming background – are fairly intuitive.

Here are some examples:

np.pi returns pi and np.sqrt() takes the square root of whatever value you feed it.

pyNp2.jpg

Trig Functions

numpy handles most common trigonometry functions.

pyNp2_1

Stats

Numpy handles many statistics functions.

Below we have mean and median. Unfortunately, just like in R, there is no mode command, but we can fake it using Set.

pyNp2_2

using set to fake mode

pyNp2_4

Numpy can also be used to find range, variance, and standard deviation.

pyNp2_5

Rounding

Numpy has rounding features for dealing with decimals. It also has floor() and ceil() functions that bring the number down to the “floor” or up to the “ceiling”

pyNp2_6

Use in creating graphs

use np.sin()

pyNp2_7.jpg

use np.log()

pyNp2_8

you can even put the two together

pyNp2_9

linspace()

My final one today is a function called linspace(). It lets you create a start and finish point, and how many elements you want. It then will create a even list of number between start and finish.

linspace(start,finish, num=numbers you want)

pyNp2_10


If you enjoyed this lesson, click LIKE below, or even better, leave me a COMMENT. 

Last Lesson: Numpy

Next Lesson: Pandas (Series)

Return to: Python for Data Science Course

Follow this link for more Python content: Python

 

 

One thought on “Python: Numpy Part II

  1. Pingback: Python: Fun with Central Tendency – Analytics4All

Leave a Reply