Skip to Main Content
It looks like you're using Internet Explorer 11 or older. This website works best with modern browsers such as the latest versions of Chrome, Firefox, Safari, and Edge. If you continue with this browser, you may see unexpected results.

Python for Basic Data Analysis: NP.12 Math with NumPy II

Get started on your learning journey towards data science using Python. Equip yourself with practical skills in Python programming for the purpose of basic data manipulation and analysis.

Math with NumPy II

When conducting an analysis, we often need to find the mean, standard deviation and minimum/maximum values.

Let's start with a 2D array, which is the most common for data analysis.
 

Simple math required for data analysis

Mean

Use .mean to find the mean of elements in an array. You can find the mean of all elements, or find the mean of elements in rows or columns by specifying the axis. 


Now let's verify the information above:

Sum

Use np.sum to sum all elements in the matrix. You can also specify the axis to sum by rows or columns. 

Standard deviation

Use np.std to find the standard deviation of all elements in the matrix. You can also specify the axis to find the standard deviation of rows or columns.

Minimum and maximum value of the array

Use .min and .max to find the minimum and maximum of the entire matrix. You can also specify the axis for rows and columns.

Exercises

Use this array for the following practice: 

myArray = np.array([[1, 2, 3], [4, 5, 6], [7, 8, 9]])


1. Find the mean of this array

2. Find the standard deviation by rows

3. Find the maximum value in the array