numpy从线性函数生成数据 [英] numpy generate data from linear function

查看:316
本文介绍了numpy从线性函数生成数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

说我想从线性函数生成100个左右的数据点,最好的方法是什么?

Say I wanted to generate 100 or so data points from a linear function what's the best way to go about it?

线性函数示例y = 0.4*x + 3 + delta

其中delta是从-10到+10之间的均匀分布得出的随机值

where delta is a random value drawn from a uniform distribution between -10 and +10

我希望为每个数据点生成增量,以便对数据进行一些扰动.

I want delta to be generated for each data point to give some perturbation to the data.

import numpy as np

d = np.random.uniform(-10, 10)

尽管我不确定确切如何生成包含此内容的其余内容,但这似乎符合delta的要求.

This seems to fit the bill for delta although I'm unsure exactly how to generate the rest incorporating this.

推荐答案

我不知道您要如何生成x,但这会起作用:

I don't know how you wanted to generate x, but this will work:

In [7]: x = np.arange(100)

In [8]: delta = np.random.uniform(-10,10, size=(100,))

In [9]: y = .4 * x +3 + delta

这篇关于numpy从线性函数生成数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆