Month: May 2018

Analyzing Stock Data with Numpy – The Reshape and Average Functions

Daily Data Science Puzzle [python] import numpy as np # apple stock prices (May 2018) prices = [ 189, 186, 186, 188, 187, 188, 188, 186, 188, 188, 187, 186 ] prices = np.array(prices) data_3day = prices.reshape(4,3) print(int(np.average(data_3day[0]))) print(int(np.average(data_3day[-1]))) [/python] What is the output of this puzzle? Numpy is a popular Python library for data …

Analyzing Stock Data with Numpy – The Reshape and Average Functions Read More »

How to Create a Sequence of Evenly Spaced Values with Numpy Linspace?

Daily Data Science Puzzle [python] import numpy as np year = np.linspace(0, 365, 366) print(int(year[-1] – year[-2])) [/python] What is the output of this puzzle? Numpy is a popular Python library for data science focusing on linear algebra. This puzzle is about the useful function linspace. In particular, linspace(start, stop, num) returns evenly spaced numbers …

How to Create a Sequence of Evenly Spaced Values with Numpy Linspace? Read More »

How to Create a Sequence of Linearly Increasing Values with Numpy Arange?

Daily Data Science Puzzle [python] import numpy as np # save $122.50 per month x = 122.5 net_wealth = np.arange(0, 1000, x) # how long to save >$1000? print(len(net_wealth)) [/python] What is the output of this puzzle? Numpy is a popular Python library for data science focusing on linear algebra. This puzzle is about the …

How to Create a Sequence of Linearly Increasing Values with Numpy Arange? Read More »

The Dimension of a Numpy Matrix

What is the output of this puzzle?   [python] import numpy as np # salary in ($1000) [2015, 2016, 2017] dataScientist = [133, 132, 137] productManager = [127, 140, 145] designer = [118, 118, 127] softwareEngineer = [129, 131, 137] a = np.array([dataScientist, productManager, designer, softwareEngineer]) print(a.ndim) [/python]   Numpy is a popular Python library …

The Dimension of a Numpy Matrix Read More »

Daily Data Science Puzzle: How to Get the Shape of a Numpy Matrix?

What is the output of this puzzle?   [python] import numpy as np # salary in ($1000) [2015, 2016, 2017] dataScientist = [133, 132, 137] productManager = [127, 140, 145] designer = [118, 118, 127] softwareEngineer = [129, 131, 137] a = np.array([dataScientist, productManager, designer, softwareEngineer]) print(a.shape[0]) print(a.shape[1]) [/python]   Numpy is a popular Python …

Daily Data Science Puzzle: How to Get the Shape of a Numpy Matrix? Read More »

Daily Python Puzzle: How to Intersect two Sets in Python?

What is the output of this puzzle? [python] # cancer-fighting foods cf = {“basil”, “berries”, “broccoli”, “curcume”, “garlic”, “kale”, “oranges”, “seeds”, “spinach”, “sprouts”} # blood pressure reducing foods bf = {“bananas”, “berries”, “fish”, “garlic”, “kale”, “red beets”, “salmon”, “seeds”, “spinach”, “yogurt”} print(len(cf & bf)) [/python] This puzzle is about two pieces of basic knowledge. The …

Daily Python Puzzle: How to Intersect two Sets in Python? Read More »

Daily Python Puzzle: How to Find the Maximum in a Dictionary?

What is the output of this puzzle?   [python] # mg per 100g omega3_table = { "Salmon" : 2260, "Hering" : 1729, "Sardines" : 1480, "Flaxseeds" : 53400, "Eggs" : 400 } y = max(omega3_table, key=lambda x : omega3_table[x]) print(y) [/python]   In this puzzle, we learn two things. First, we can retrieve the maximal …

Daily Python Puzzle: How to Find the Maximum in a Dictionary? Read More »

How to Boost your Logic Skills (Series)? The “in” and “is” Keywords.

What is the output of this puzzle?   [python] meal_1 = "Meat" meal_2 = "Flaxseeds" meal_3 = "Marshmallows" healthyFoods = ["Kale", "Apple", "Strawberry", "Banana", "Flaxseeds"] def isHealthy(food): return food in healthyFoods m_1 = isHealthy(meal_1) m_2 = isHealthy(meal_2) m_3 = isHealthy(meal_3) print((not m_1 or m_2) and (meal_2 is "Flaxseeds") and isHealthy("Kale")) [/python]   This puzzle shows …

How to Boost your Logic Skills (Series)? The “in” and “is” Keywords. Read More »