我就废话不多说了,直接上代码吧!

import numpy as np
import matplotlib.pyplot as plt


def gen_clusters():
  mean1 = [0,0]
  cov1 = [[1,0],[0,10]]
  data = np.random.multivariate_normal(mean1,cov1,100)
  
  mean2 = [10,10]
  cov2 = [[10,0],[0,1]]
  data = np.append(data,
           np.random.multivariate_normal(mean2,cov2,100),
           0)
  
  mean3 = [10,0]
  cov3 = [[3,0],[0,4]]
  data = np.append(data,
           np.random.multivariate_normal(mean3,cov3,100),
           0)
  
  return np.round(data,4)

def save_data(data,filename):
  with open(filename,'w') as file:
    for i in range(data.shape[0]):
      file.write(str(data[i,0])+','+str(data[i,1])+'\n')
      
def load_data(filename):
  data = []
  with open(filename,'r') as file:
    for line in file.readlines():
      data.append([ float(i) for i in line.split(',')])
  return np.array(data)

def show_scatter(data):
  x,y = data.T
  plt.scatter(x,y)
  plt.axis()
  plt.title("scatter")
  plt.xlabel("x")
  plt.ylabel("y")
  
data = gen_clusters()
save_data(data,'3clusters.txt')
d = load_data('3clusters.txt')
show_scatter(d)

python 多维高斯分布数据生成方式

以上这篇python 多维高斯分布数据生成方式就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持。

广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!