import numpy as np
Bees = open("BeesData.txt", "r")
Bees = Bees.read()
Bees = Bees.split( )
for i in range(0, len(Bees)):
Bees[i] = int(Bees[i])
Bees = np.reshape(Bees,(25,25))
def suma5x5(x,y):
suma=0
这是BeesData文件:
https://drive.google.com/file/d/1aWcLZq2MuGENavoTnCfokXr1Nnyygz23/view?usp=sharing![enter图像描述在此](https://i.stack.imgur.com/G9u5P.png)
我把这当作是一种学习练习。不是真正的
numpy
用户TLDR:
假设5个相邻的意思是:上、下、左、右、中,那么你可以用卷积法找到这个值
假设我们只想找到标记为1的值的每个3x3块的总和:
此形状可以用作卷积的内核。它将用于将3x3平方中的每个值相加,将其相应的值乘以1。e、 g代表
你会得到
1x0 + 2x1 + 3x0 + 4x1 + 5x1 + 6x1 + 7x0 + 8x1 + 9x0 = 25
scipy
有一个用于此的方法称为convolve2d
这将产生:
因为我们将边作为卷积的一部分包括在内,所以您将看到结果大小现在是8x8,而不是原来的6x6。对于由于超出数组边缘而无法找到的值,该方法假定值为零
要放弃这些边,可以使用
same
模式,该模式使其从结果中删除这些边:现在要找到蜜蜂最多的位置,可以使用
argmax
获得最大值的索引,并使用unravel_index
将其作为原始形状中的位置假设最后两行代码的窗口大小为5x5:
尝试了一个简单的基本python+numpy操作代码
相关问题 更多 >
编程相关推荐