Key Concepts

Review core concepts you need to learn to master this subject

NumPy’s Mean and Axis

We will use the following 2-dimensional array for this example: ``` py ring_toss = np.array([[1, 0, 0], [0, 0, 1], [1, 0, 1]]) ``` The code below will calculate the average of each row. ```py np.mean(ring_toss, axis=1) # Output: array([ 0.33333333, 0.33333333, 0.66666667]) ```

In a two-dimensional array, you may want the mean of just the rows or just the columns. In Python, the NumPy .mean() function can be used to find these values. To find the average of all rows, set the axis parameter to 1. To find the average of all columns, set the axis parameter to 0.

Introduction to Statistics with NumPy
Lesson 1 of 2

What you'll create

Portfolio projects that showcase your new skills

Pro Logo

How you'll master it

Stress-test your knowledge with quizzes that help commit syntax to memory

Pro Logo