pythonnumpy
Ben Gorman

Ben Gorman

Life's a garden. Dig it.

You're given a 10x2 array of floats where each row represents a movie. The first column represents the movie's rating and the second column represents the director's rating.

import numpy as np
 
generator = np.random.default_rng(123)
ratings = np.round(generator.uniform(low=0.0, high=10.0, size=(10, 2)))
ratings[[1,2,7,9], [0,0,0,0]] = np.nan
 
print(ratings)
# [[ 7.  1.]
#  [nan  2.]
#  [nan  8.]
#  [ 9.  3.]
#  [ 8.  9.]
#  [ 5.  2.]
#  [ 8.  2.]
#  [nan  6.]
#  [ 9.  2.]
#  [nan  5.]]

Create a third column that represents the overall rating. The overall rating is equal to the movie rating if it exists, otherwise the director's rating.


Solution 1

This content is gated

Subscribe to one of the products below to gain access

Solution 2

This content is gated

Subscribe to one of the products below to gain access