【问题标题】:Is there a Python method for creating a custom convolution?是否有用于创建自定义卷积的 Python 方法?
【发布时间】:2020-03-30 22:11:08
【问题描述】:
我正在尝试为每个细胞创建一个有效的全元细胞自动机实现,每个细胞具有三种可能的颜色,就像 Stephen Wolfram 的书 A New Kind of Science 中的这张图片一样:
如果我有一个numpy 数组,我是否可以创建一个新的numpy 数组,方法是让一个宽度为 3 的窗口滑过原始数组,添加三个元素,然后使用这个总和作为外观的索引规则的-up 表?
我在想我可以使用np.correlate,但这不会在规则数组中进行查找。也许我以后可以用地图做到这一点。
【问题讨论】:
标签:
python
numpy
cellular-automata
【解决方案1】:
a = self.array
i = self.next
window = [1, 1, 1]
row = self.array[i - 1]
correlated_row = np.correlate(row, window, mode="same")
next_row = np.array([self.table[7 - total - 1] for total in correlated_row])
a[i] = next_row
self.next += 1