简体   繁体   English

使用numpy.random

[英]Using numpy.random

I'm having a little bit of trouble using numpy.random.normal. 我在使用numpy.random.normal时遇到了一些麻烦。 At the bottom of this link ( http://docs.scipy.org/doc/numpy/reference/generated/numpy.random.normal.html ) there's a graph which shows standard deviations. 在这个链接的底部( http://docs.scipy.org/doc/numpy/reference/generated/numpy.random.normal.html ),有一个显示标准偏差的图表。 I'm a little confused about this, because it doesn't look like 0.1, 0.2, 0.3 etc. standard deviations. 我对此有点困惑,因为它看起来不像0.1,0.2,0.3等标准偏差。 It also doesn't look like 1, 2, or 3 standard deviations. 它也看起来不像1,2或3个标准偏差。

What I'm trying to do is to add noise to an image at specific standard deviations. 我要做的是在特定的标准偏差下为图像添加噪点。 However, the results I get are honestly pretty weird. 但是,我得到的结果实在是非常奇怪。 My code (in Python) is shown below: 我的代码(在Python中)如下所示:

poisson = float((raw_input("Noise standard deviation: ")))
.
.
.
name = t+'PHOTO'+s+str(i)+'.fits'

    im = pf.open(name)
    isinstance(im,list)
    im0 = im[0]
    poissonNoise = np.random.normal(0,poisson/1000, im0.data.shape).astype(float)
    test = im0.data + poissonNoise
    im0.data = test
    stringee = 'NOISE'
    pf.writeto(stringee+str(poisson)+name, data=test, clobber=True, header=im0.header)
print poisson

If you notice, I divide "poisson" by 1000 in order to get meaningful results. 如果您注意到,我将“泊松”除以1000以获得有意义的结果。 So what is the real value of the standard deviation, and how do I use it? 那么标准差的真正价值是什么,我该如何使用呢? All I want to do is to be able to input 1, 2, 3, etc. standard deviations and create that much noise. 我想做的就是能够输入1,2,3等标准偏差并产生很大的噪音。

It seems you're mixing things together. 看来你在混合各种东西。 On the figure of discussion in the question 关于问题中的讨论数字

在此输入图像描述

X axis is just X values not Standard Deviations . X轴只是X而不是 Standard Deviations Remember that, for one distribution (here, Normal ) there is only one single value standard deviation which can be computed easily, numpy.std . 请记住,对于一个分布(此处为Normal ),只有一个单值标准偏差可以轻松计算, numpy.std

BTW, your code is not quiet Python code. 顺便说一下,你的代码不是安静的Python代码。 What is this: isinstance(im,list) for? 这是什么: isinstance(im,list) for? Also remember that, indentation is heart of Python. 还要记住,缩进是Python的核心。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM