Run the cell below to see an example of a comparison operator in action.
Get answer to your question and much more
Arrays are compatible with comparison operators. The output is an array of boolean values.In [5]:make_array(1,5,7,8,3,-1)> 3Out[5]:array([False,True,True,True, False, False])One day, when you come home after a long week, you see a hot bowl of nachos waiting onthe dining table! Let’s say that whenever you take a nacho from the bowl, it will either have onlycheese, onlysalsa,bothcheese and salsa, orneithercheese nor salsa (a sad tortilla chip indeed).Let’stryandsimulatetakingnachosfromthebowlatrandomusingthefunction,np.random.choice(arr), wherearris the array that you’re using. Start by running the cell belowseveral times, and observe how the results change.
Get answer to your question and much more
Question 1.Assume we took ten nachos at random, and stored the results in an array calledten_nachosas done below. Find the number of nachos with only cheese using code (do not hard-code the answer).Hint:Our solution involves a comparison operator and thenp.count_nonzeromethod.
Get answer to your question and much more