Who Dominates Instagram or Comparing Each Element of a Numpy Array

Daily Data Science Puzzle

import numpy as np

# popular instagram accounts
# (millions followers)
inst = [232, #"@instagram"
133, #"@selenagomez"
59, #"@victoriassecret"
120, #"@cristiano"
111, #"@beyonce"
76] #"@nike"

inst = np.array(inst)
superstars = inst > 100

What is the output of this puzzle?

Numpy is a popular Python library for data science focusing on linear algebra.

The following handy numpy feature will prove useful throughout your career. You can use comparison operators directly on numpy arrays. The result is an equally-sized numpy array with boolean values. Each boolean indicates whether the comparison evaluates to True for the respective value in the original array.

The puzzle creates a list of integers. Each integer represents the number of followers of popular Instagram accounts (in millions). First, we convert this list to a numpy array. Then, we determine for each account whether it has more than 100 million followers.

We print the first and the third boolean value of the resulting numpy array. The result is True for @instagram with 232 million followers and False for @victoriassecret with 59 million followers.

Are you a master coder?
Test your skills now!

Related Video




Leave a Comment

Your email address will not be published. Required fields are marked *