Numpy Statistics Flashcards
What is the standard import procedure for numpy?
import numpy as np
How do you generate a list of 10000 random normalized data points, centered at “x” with standard deviation of “y”.
list_name = np.random.normal(x,y,10000)
How do you get the mean of a numpy list?
list_mean = np.mean(list_name)
How do you get the median of a numpy list?
list_median = np.median(list_name)
How do you generate a list of 10000 random integers, ranging from “x” to “y”?
list_name = np.random.randint(x,y,10000)
How do you get the mode of a numpy list (remember the import statement)?
from scipy import stats
list_mode = stats.mode(list_name)
How do you get the standard deviation of a numpy list?
list_std = list_name.std()
How do you get the variance of a numpy list?
list_var = list_name.var()
How do you generate a list of 10000 random uniform data points, ranging from “x” to “y”?
list_name = np.random.uniform(x,y,10000)
How do you generate an evenly-spaced list of numbers from x to y with a spacing of “gap”?
list_name = np.arange(-3, 3, 0.001)
How do you visualize the probability density function with a given list (include necessary import statements)?
from scipy.stats import norm
…
plt.plot(list_name, norm.pdf(list_name))
How do you visualize the exponential probability density function with a given list (include necessary import statements)?
from scipy.stats import expon
…
plt.plot(list_name, expon.pdf(list_name))
How do you visualize the binomial probability mass function with a given list (include necessary import statements)?
from scipy.stats import binom
import matplotlib.pyplot as plt
n, p = 10, 0.5
list_name = np.arange(0, 10, 0.001)
plt.plot(list_name, binom.pmf(list_name, n, p))
How do you visualize the Poisson probability mass function with a given list (include necessary import statements)?
from scipy.stats import poisson
import matplotlib.pyplot as plt
mu = 500
list_name = np.arange(400, 600, 0.5)
plt.plot(x, poisson.pmf(list_name, mu))
How do you calculate the nth percentile of a numpy list?
per = np.percentile(list_name,n)