Skip to content

Love Distance Problem


You’re a relationship scientist, and you’ve developed a questionnaire that determines a person’s love score - a real-valued number between 0 and 100. Your theory is that two people with similar love scores should make a good match 👩‍❤️‍💋‍👨

Given the love scores for 10 different people, create a 2-d array where (i,j) gives the absolute difference of the love scores for person i and person j.

import numpy as np

generator = np.random.default_rng(1010)
love_scores = np.round(generator.uniform(low=0, high=100, size=10), 2)

print(love_scores)
# [ 9.5  53.58 91.77 98.15 84.88 74.61 40.94 56.49  8.39 64.69]
NumPy line wrapping tip

The 10x10 array you're about to build is kind of large. When printing the array in your console, NumPy might wrap the rows into multiple lines like this

numpy line wrapping

To prevent line wrapping, use np.set_printoptions(linewidth=100000)

numpy line wrapping 2

See set_printoptions() for details.


Try with Google Colab See the solution