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 ############################################### ...
随机推荐
- php生成随机密码的自定义函数
php生成随机密码的自定义函数 生成一个随机密码的函数,生成的密码为小写字母与数字的随机字符串,长度可自定义. 复制代码代码如下: <?php /* * php自动生成新密码自定义函数(带实例 ...
- [原创]java WEB学习笔记21:MVC案例完整实践(part 2)---DAO层设计
本博客为原创:综合 尚硅谷(http://www.atguigu.com)的系统教程(深表感谢)和 网络上的现有资源(博客,文档,图书等),资源的出处我会标明 本博客的目的:①总结自己的学习过程,相当 ...
- 【leetcode刷提笔记】Permutations
Given a collection of numbers, return all possible permutations. For example,[1,2,3] have the follow ...
- Fermat’s Chirstmas Theorem (素数打表的)
Fermat’s Chirstmas Theorem ...
- 剑指offer之 奇数偶数数组位置调整且保存顺序不变
public class Solution { public void reOrderArray(int [] array) { reOrderCore(array,array.length); } ...
- 创建HTML5/CSS3单页Web布局
1. [图片] 第1步:PhotoShop 2. [代码]第2步:index.html <!DOCTYPE html><!-- The new doctype -->< ...
- 分享知识-快乐自己:ActiveMQ 安装部署
1):下载 ActiveMQ tar 包 2):上传到 服务器中 3):解压到 指定目录中 [root@admin tools]# tar -zxvf apache-activemq-5.2.0-bi ...
- Winform中的dataGridView添加自动编号
1.Winform中的dataGridView添加自动编号:http://blog.csdn.net/ohyoyo2014/article/details/38346887 2.如何为datagrid ...
- docker 安装过程
- python 标准库 —— http(http.cookiejar)
1. cookie 信息的读取 from urllib import request import http from http import cookiejar cookie = cookiejar ...