numpy2
统计相关
次序统计
计算最小值
numpy.amin(a[, axis=None, out=None, keepdims=np._NoValue, initial=np._NoValue, where=np._NoValue])Return the minimum of an array or minimum along an axis.
计算最大值
numpy.amax(a[, axis=None, out=None, keepdims=np._NoValue, initial=np._NoValue, where=np._NoValue])Return the maximum of an array or maximum along an axis.
计算极差
numpy.ptp(a, axis=None, out=None, keepdims=np._NoValue) Range of values (maximum - minimum) along an axis. The name of the function comes from the acronym for ‘peak to peak’.
计算分位数
numpy.percentile(a, q, axis=None, out=None, overwrite_input=False, interpolation=‘linear’, keepdims=False) Compute the q-th percentile of the data along the specified axis. Returns the q-th percentile(s) of the array elements.
a:array,用来算分位数的对象,可以是多维的数组。
q:介于0-100的float,用来计算是几分位的参数,如四分之一位就是25,如要算两个位置的数就[25,75]。
axis:坐标轴的方向,一维的就不用考虑了,多维的就用这个调整计算的维度方向,取值范围0/1。
均值与方差
计算中位数
numpy.median(a, axis=None, out=None, overwrite_input=False, keepdims=False) Compute the median along the specified axis. Returns the median of the array elements.
计算平均值
numpy.mean(a[, axis=None, dtype=None, out=None, keepdims=np._NoValue)])Compute the arithmetic mean along the specified axis.
计算加权平均值
numpy.average(a[, axis=None, weights=None, returned=False])Compute the weighted average along the specified axis.
mean和average都是计算均值的函数,在不指定权重的时候average和mean是一样的。指定权重后,average可以计算加权平均值。
计算方差
numpy.var(a[, axis=None, dtype=None, out=None, ddof=0, keepdims=np._NoValue])Compute the variance along the specified axis.
ddof=0:是“Delta Degrees of Freedom”,表示自由度的个数。
要注意方差和样本方差的无偏估计,方差公式中分母上是n;样本方差无偏估计公式中分母上是n-1(n为样本个数)。
计算标准差
numpy.std(a[, axis=None, dtype=None, out=None, ddof=0, keepdims=np._NoValue])Compute the standard deviation along the specified axis.
标准差是一组数据平均值分散程度的一种度量,是方差的算术平方根。
相关
计算协方差矩阵
image
image
739×199 18.2 KB
numpy.cov(m, y=None, rowvar=True, bias=False, ddof=None, fweights=None,aweights=None) Estimate a covariance matrix, given data and weights.
计算相关系数
numpy.corrcoef(x, y=None, rowvar=True, bias=np._NoValue, ddof=np._NoValue) Return Pearson product-moment correlation coefficients.
理解了np.cov()函数之后,很容易理解np.correlate(),二者参数几乎一模一样。
np.cov()描述的是两个向量协同变化的程度,它的取值可能非常大,也可能非常小,这就导致没法直观地衡量二者协同变化的程度。相关系数实际上是正则化的协方差,n个变量的相关系数形成一个n维方阵。
直方图
numpy.digitize(x, bins, right=False)Return the indices of the bins to which each value in input array belongs.
x:numpy数组
bins:一维单调数组,必须是升序或者降序
right:间隔是否包含最右
返回值:x在bins中的位置。