Python / Data Science Essentials Interview Questions
What are the most commonly used NumPy mathematical functions in data science?
NumPy ships a comprehensive set of universal functions (ufuncs) — compiled, vectorised operations that apply element-wise across the full array without Python loops. Knowing these avoids writing slow manual loops for standard computations.
import numpy as np
a = np.array([1.0, 4.0, 9.0, 16.0, 25.0])
# Element-wise math
np.sqrt(a) # [1. 2. 3. 4. 5.]
np.log(a) # natural log
np.log2(a) # base-2 log
np.log10(a) # base-10 log
np.exp(a) # e^x
np.abs(np.array([-3, 4, -1])) # [3 4 1]
# Aggregation
a.sum() # 55.0
a.mean() # 11.0
a.std() # standard deviation
a.var() # variance
a.min(); a.max() # extremes
a.argmin(); a.argmax() # INDEX of min/max
np.median(a) # 9.0
np.percentile(a, 75) # 75th percentile
# Linear algebra
A = np.array([[1, 2], [3, 4]])
B = np.array([[5, 6], [7, 8]])
np.dot(A, B) # matrix multiplication (also A @ B in Python 3.5+)
np.linalg.inv(A) # matrix inverse
np.linalg.det(A) # determinant
vals, vecs = np.linalg.eig(A) # eigenvalues and eigenvectors
# Sorting
unsorted = np.array([3, 1, 4, 1, 5])
np.sort(unsorted) # returns sorted copy: [1 1 3 4 5]
np.argsort(unsorted) # indices that would sort: [1 3 0 2 4]
Invest now in Acorns!!! 🚀
Join Acorns and get your $5 bonus!
Acorns is a micro-investing app that automatically invests your "spare change" from daily purchases into diversified, expert-built portfolios of ETFs. It is designed for beginners, allowing you to start investing with as little as $5. The service automates saving and investing. Disclosure: I may receive a referral bonus.
Invest now!!! Get Free equity stock (US, UK only)!
Use Robinhood app to invest in stocks. It is safe and secure. Use the Referral link to claim your free stock when you sign up!.
The Robinhood app makes it easy to trade stocks, crypto and more.
Webull! Receive free stock by signing up using the link: Webull signup.
More Related questions...
