# Python NumPy For Your Grandma - 5.5 Challenge: The Game of Doors

Contents

## Setup

You’re preparing for a game show where you play the following game.

You’re faced with four doors. Behind one door is cash money, and behind the other three doors is steaming pile of broccoli. If you pick the door with money, you get the option to play again at the risk of losing the money you’ve collected thus far. If you keep winning, you can play a maximum of three rounds before the game show host kicks you off his show.

You have some strategy ideas you’d like to evaluate before you go on the show. So you hired an unpaid intern to scour through historic recordings of the show and log data on where prizes were located and the value of each prize. Your intern gets back to you with the following matrices:

• `prize_doors`: Here, element (i,j) gives the door hiding the prize in round j of the ith game
• `prizes`: Here (i, j) gives the prize amount in round j of the ith game

Build a 5x3x4 matrix where (i,j,k) represents the prize behind door k of round j of game i.

``````import numpy as np

prize_doors = np.array([
[1, 0, 2],
[0, 0, 1],
[3, 3, 1],
[1, 2, 0],
[2, 1, 1]
])

prizes = np.array([
[100, 150, 500],
[200, 300, 250],
[150, 100, 325],
[425, 200, 100],
[200, 250, 300]
])
``````

## Solution

``````answer = np.zeros((5, 3, 4))
answer[np.arange(5)[:, None], np.arange(3)[None, :], prize_doors] = prizes
## [[[  0. 100.   0.   0.]
##   [150.   0.   0.   0.]
##   [  0.   0. 500.   0.]]
##
##  [[200.   0.   0.   0.]
##   [300.   0.   0.   0.]
##   [  0. 250.   0.   0.]]
##
##  [[  0.   0.   0. 150.]
##   [  0.   0.   0. 100.]
##   [  0. 325.   0.   0.]]
##
##  [[  0. 425.   0.   0.]
##   [  0.   0. 200.   0.]
##   [100.   0.   0.   0.]]
##
##  [[  0.   0. 200.   0.]
##   [  0. 250.   0.   0.]
##   [  0. 300.   0.   0.]]]
``````