Try it on paper first. A hint, the key idea and the worked solution are here when you need them.
Four players played three games. The scores are the rows of this table:
[[12, 15, 9], [20, 18, 22], [14, 10, 16], [8, 11, 13]]
Find the total of each player, the best player (counting from 0), and the average of each game. Then find, for each game, how many players scored more than the average of that game.
Have you tried it?
Work it out on paper first. It is fine to get stuck or make a mistake: that is how we learn. When you are ready, go through the solution one step at a time, and check each step against your own.
Plan. Each player is a row, so the totals use axis=1. Each game is a column, so the game averages use axis=0. Comparing the table with the row of averages uses broadcasting.
Check. The totals are 36, 60, 40 and 32. The biggest is the player 1. The game averages are 13.5, 13.5 and 15.0. For the first game, the players with more than 13.5 are the ones with 20 and 14: two. For the second game, the scores above 13.5 are 15 and 18: two. For the third game, above 15 are 22 and 16: two.
Answer: totals [36 60 40 32], best player 1, averages [13.5 13.5 15. ], and [2 2 2] players above the average.
Log in to join the discussion.
Loading…