小编Dan*_*ard的帖子

如何在有位置限制的情况下找到 numpy 数组的最大值?

我在 python 2.7 中有一个 numpy 数组,我使用 imshow() 函数对其进行可视化。生成数组的代码如下所示:

from pylab import *
r0 = 3.0
S0 = 10.0
x = zeros((101,101))
noiseimg = zeros((101,101))
for i in range(101):
    for j in range(101):
        noiseimg[i,j] = noiseimg[i,j] + normal(3,1)
mean_i = randint(0,101)
mean_j = randint(0,101)

for i in range(101):
    for j in range(101):
        r = ((i-mean_i)**2 + (j-mean_j)**2)**0.5
        x[i,j] = S0*(1+(r/r0)**2)**-1.5
        x[i,j] = x[i,j] + noiseimg[i,j]
        if (((i-50)**2 + (j-50)**2)**0.5 >= 40) and (((i-50)**2 + (j-50)**2)**0.5 <= 41):
            x[i,j]=0
imshow(x)
show()
Run Code Online (Sandbox Code Playgroud)

其作用是生成一张具有一定背景噪声水平的图像和一个圆形对称源。图像上有一个以 …

python arrays numpy python-2.7

3
推荐指数
1
解决办法
3283
查看次数

标签 统计

arrays ×1

numpy ×1

python ×1

python-2.7 ×1