python - 如何组合/联合两个单独的 numpy 高斯集?
问题描述
我想组合两个独立的随机高斯数据集,一个有自己的均值和标准,另一个有离群均值和标准。我的代码是这样的:
import random
import numpy as np
import numpy.random as ra
from numpy.random import seed
#This makes the random numbers generated not change when rerunning the code
np.random.seed(0)
#Creating two Gaussian sets, one with mean 0 and std 1, the second is outlier with mean 3 and std 1
#Each set contains 1,000 trials, first set contains 99 points while outlier set contains 1 point for each trial (for 1% outlier)
data = np.random.normal(loc=0, scale=1, size=(1000, 99))
dataoutlier = np.random.normal(loc=3, scale=1, size=(1000, 1))
现在我怎样才能将它结合起来,使异常值与每次试验的第一组一致?我认为使用 np.union1d 会起作用,但这会将所有试验组合成一个巨大的数组。任何帮助将不胜感激!
解决方案
为了按列组合两个 numpy 数组,您可以使用append方法。
np.append(data, dataoutlier, axis=1)
推荐阅读
- r - QAP分析如何保证行名和列名顺序一致
- python - 如何纠正 IndexError
- c++ - C++中的概念多态性
- python - 在 Python 中用图片训练 SVM
- c# - 如何在不创建新数组的情况下更改数组中元素的数量
- android - 作为系统应用程序运行时,Android 不允许执行本机库
- c++ - 错误:无法将“float”转换为“float*”作为参数
- angularjs - 角度 1.x 是否仍然相关
- php - 无法在 OneNote 共享笔记本中获取分区
- apache-spark - spark-submit 适用于 yarn-cluster 模式,但 SparkLauncher 不适用,具有相同的参数