# -*- coding:utf-8 -*- import numpy as np from scipy import stats import math import matplotlib as mpl import matplotlib.pyplot as plt from mpl_toolkits.mplot3d import Axes3D from matplotlib import cm def calc_statistics(x): n = x.shape[0] #样本个数 m = 0#期望 m2 = 0#平方的期望 m3 = 0#三次方的期望 m4 = 0#四次方的期望 for t in x: #向量的加法 m += t m2 += t*t m3 += t**3 m4 += t**4 m /= n m2 /= n m3 /= n m4 /= n #标准差 = E((X - E(X))^2) = E(X^2) - E(X)^2 sigma = np.sqrt(m2-m*m) #求偏度 = E((X-E(X))^3) = (m3 - 3*m*m2 + 2*m**3) / sigma**3 skew = (m3 - 3*m*sigma**2 - m**3) / sigma**3 #求峰度 kurtosis = m4 / sigma**4 - 3 print('手动计算均值、标准差、偏度、峰度:', m, sigma, skew, kurtosis) #使用系统函数验证 mu = np.mean(x,axis=0) sigma = np.std(x,axis=0) skew = stats.skew(x) kurtosis = stats.kurtosis(x) return mu,sigma,skew,kurtosis if __name__ == '__
python二维正态分布
最新推荐文章于 2023-08-14 15:57:23 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)