Python | Overview of NUMPY exercise | Create, slice and sum array of Tokyo Olympics medals table

This exercise is provided to allow potential course delegates to choose the correct Wise Owl Microsoft training course, and may not be reproduced in whole or in part in any format without the prior written consent of Wise Owl.

You can learn how to do this exercise if you attend the course listed below!

Software ==> Python  (25 exercises)
Version ==> Latest version
Topic ==> Overview of NUMPY  (1 exercise)
Level ==> Relatively easy
Classroom ==> Python programming
Online ==> Python programming

You need a minimum screen resolution of about 700 pixels width to see our exercises. This is because they contain diagrams and tables which would not be viewable easily on a mobile phone or small laptop. Please use a larger tablet, notebook or desktop computer, or change your screen resolution settings.

Total medals won by the top 5 countries at the Tokyo 2021 Olympics are shown below:

Medals table

Go, United Kingdom!

Import the numpy module, and create a NumPy array to hold this information (including the country number).  Here's what this should look like if you print it out:

The initial array

The array should show the countries in rows and the country number and gold, silver and bronze medal count in columns (there's no need to store the total medal count - we can calculate that).


Use slicing to create another array to hold all of the rows of the first one, and all of the columns bar the first one:

Reduced array

The reduced array, excluding the country numbers.


Sum the array along the second axis to return the total number of medals won by each country:

Total medals won

China won more gold medals than the UK and the ROC, but less overall medals.


Close your program down!

You can unzip this file to see the answers to this exercise, although please remember this is for your personal use only.
This page has 0 threads Add post