numpy.mean和numpy.random.multivariate_normal(依据均值和协方差生成数据,提醒:计算协方差别忘了转置)
>> import numpy as np
>>> A1_mean = [1, 1]
>>> A1_cov = [[2, .99], [1, 1]]
>>> A1 = np.random.multivariate_normal(A1_mean, A1_cov, 10) #依据指定的均值和协方差生成数据
>>> A1
array([[-1.72475813, 0.33681971],
[ 0.78643798, 0.76700529],
[ 0.61538183, -0.75786666],
[ 2.85758498, 2.55947038],
[ 1.78292279, 0.75539859],
[ 1.51245811, 2.2377212 ],
[ 1.86063512, 0.89370386],
[ 0.40500526, 0.83009172],
[ 1.39342622, 1.66581794],
[-1.75143864, -0.39855419]])
>>> np.mean(A1) #求全体数的均值
0.83136316789824638
>>> np.mean(A1,axis=0) #按列求均值(每列为一组),和预设有点差距
array([ 0.77376555, 0.88896078])
>>> np.mean(A1,axis=1)#按行求均值(每行为一组)
array([-0.69396921, 0.77672163, -0.07124242, 2.70852768, 1.26916069,1.87508966, 1.37716949, 0.61754849, 1.52962208, -1.07499641])
>>> np.cov(A1.T) #转置后求协方差,和预设的差不多
array([[ 2.2502378 , 1.08232076],
[ 1.08232076, 1.10267326]])
>> np.cov(A1).shape #没有转置,就是10*10的矩阵了
(10, 10)
>>> np.cov(A1)
array([[ 2.12505159e+00, -2.00310018e-02, -1.41552934e+00,-3.07293225e-01, -1.05916056e+00, 7.47593157e-01,-9.96702035e-01, 4.38174408e-01, 2.80778370e-01,1.39453830e+00],
[ -2.00310018e-02, 1.88814725e-04, 1.33429563e-02,2.89658432e-03, 9.98377972e-03, -7.04690648e-03,9.39503788e-03, -4.13028670e-03, -2.64665199e-03,-1.31450922e-02],
[ -1.41552934e+00, 1.33429563e-02, 9.42905719e-01,2.04692712e-01, 7.05523031e-01, -4.97983225e-01,6.63918454e-01, -2.91874668e-01, -1.87030762e-01,-9.28923268e-01],
[ -3.07293225e-01, 2.89658432e-03, 2.04692712e-01,4.44361569e-02, 1.53159982e-01, -1.08105757e-01,1.44128163e-01, -6.33622388e-02, -4.06019746e-02,-2.01657302e-01],
[ -1.05916056e+00, 9.98377972e-03, 7.05523031e-01,1.53159982e-01, 5.27902989e-01, -3.72612687e-01,4.96772636e-01, -2.18393309e-01, -1.39944543e-01,-6.95060753e-01],
[ 7.47593157e-01, -7.04690648e-03, -4.97983225e-01,-1.08105757e-01, -3.72612687e-01, 2.63003275e-01,-3.50639779e-01, 1.54149758e-01, 9.87778314e-02,4.90598577e-01],
[ -9.96702035e-01, 9.39503788e-03, 6.63918454e-01,1.44128163e-01, 4.96772636e-01, -3.50639779e-01,4.67478036e-01, -2.05514692e-01, -1.31692037e-01,6.54073135e-01],
[ 4.38174408e-01, -4.13028670e-03, -2.91874668e-01,-6.33622388e-02, -2.18393309e-01, 1.54149758e-01,-2.05514692e-01, 9.03492470e-02, 5.78950160e-02,2.87546427e-01],
[ 2.80778370e-01, -2.64665199e-03, -1.87030762e-01,-4.06019746e-02, -1.39944543e-01, 9.87778314e-02,-1.31692037e-01, 5.78950160e-02, 3.70986254e-02,1.84257263e-01],
[ 1.39453830e+00, -1.31450922e-02, -9.28923268e-01,-2.01657302e-01, -6.95060753e-01, 4.90598577e-01,-6.54073135e-01, 2.87546427e-01, 1.84257263e-01,9.15148164e-01]])
>>>
numpy.mean和numpy.random.multivariate_normal(依据均值和协方差生成数据,提醒:计算协方差别忘了转置)的更多相关文章
- 利用pandas和numpy计算表中每一列的均值
import numpy as np import pandas as pd df = pd.DataFrame({'var1':np.random.rand(100), #生成100个0到1之间的随 ...
- numpy.random.random & numpy.ndarray.astype & numpy.arange
今天看到这样一句代码: xb = np.random.random((nb, d)).astype('float32') #创建一个二维随机数矩阵(nb行d列) xb[:, 0] += np.aran ...
- np.random.multivariate_normal方法浅析
从多元正态分布中抽取随机样本. 多元正态分布,多正态分布或高斯分布是一维正态分布向更高维度的推广.这种分布由其均值和协方差矩阵来确定.这些参数类似于一维正态分布的平均值(平均值或"中心&qu ...
- numpy学习笔记 - numpy常用函数、向量化操作及基本数学统计方法
# -*- coding: utf-8 -*-"""主要记录代码,相关说明采用注释形势,供日常总结.查阅使用,不定时更新.Created on Fri Aug 24 19 ...
- python numPy模块 与numpy里的数据类型、数据类型对象dtype
学习链接:http://www.runoob.com/numpy/numpy-tutorial.html 官方链接:https://numpy.org/devdocs/user/quickstart. ...
- numpy学习笔记 - numpy数组的常见用法
# -*- coding: utf-8 -*- """ 主要记录代码,相关说明采用注释形势,供日常总结.查阅使用,不定时更新. Created on Mon Aug 20 ...
- numpy.stack和numpy.concatenate的区别
在使用numpy进行矩阵运算的时候踩到的坑,原因是不能正确区分numpy.concatenate和numpy.stack在功能上的差异. 先说numpy.concatenate,直接看文档: nump ...
- python 中range numpy.arange 和 numpy.linspace 的区别
1.返回值不同 range返回一个range对象,numpy.arange和numpy.linspace返回一个数组. 2.np.arange的步长可以为小数,但range的步长只能是整数. 与Pyt ...
- python numpy.shape 和 numpy.reshape函数
导入numpy模块 from numpy import * import numpy as np ############################################### ...
随机推荐
- mysql 分页测试,
大环境:MySQL5.6 自己造了 27万数据, 一次性 查出来,会超时: 而分页跑,会查出来8s: 但是在少于27万时,直接查比 分页查快5倍:
- RLearning第1弹:初识R语言
R作为一种统计分析软件,是集统计分析与图形显示于一体的.体积小.开源.很强的互动性.自从学了R本人就很少再用matlab了... 一.R语言由函数和赋值构成. R使用<-(最好养成使用习惯),而 ...
- SQL性能优化常用语句(摘录网上)
1.把trace文件导入到表中 , ) AS RowNumber,* into TableName FROM fn_trace_gettable('trace.trc', default) 2.查询C ...
- ubuntu sudo-update出错Encountered a section with no Package: header
Reading package lists... Error! E: Encountered a section with no Package: header E: Problem with Mer ...
- iOS UITableView滚动头图 拉伸放大效果 (头部弹性效果) 增加iOS11支持 附有demo
今天修改日期为2017年11月25日 两个月前做了iOS11的bug修复,才对博客进行更新,见谅. 在iOS11上需要注意两个问题 1.使用UIScrollview,UITableView,UIWeb ...
- iOS uitableViewCell 选中 push后返回 取消选中状态
首先我有一个UITableViewController,其中每个UITableViewCell点击后都会push另一个 ViewController,每次点击Cell的时候,Cell都会被选中,当从p ...
- python neo4j
https://neo4j.com/developer/python/ http://debian.neo4j.org/
- Data Structure Array: Longest Monotonically Increasing Subsequence Size
http://www.geeksforgeeks.org/longest-monotonically-increasing-subsequence-size-n-log-n/ #include < ...
- Data Structure Array: Maximum of all subarrays of size k
http://www.geeksforgeeks.org/maximum-of-all-subarrays-of-size-k/ #include <iostream> #include ...
- redis配置参数的热修改
Redis使用config命令,可以对配置项参数热修改,不必重启. Redis最好不要重启,重启一次会引发如下问题: 如果数据很多(例如几个G),读起来很慢: 重启风险很大,Redis有内存陷阱 重启 ...