小编sov*_*el2的帖子

Eller 算法的问题 - 迷宫生成

我正在尝试使用埃勒算法创建一个迷宫。互联网上关于这个特定算法的信息并不多。所以我对这个算法有一些困难,因为有些事情我不完全理解。但无论如何,这就是我现在所拥有的:

\n\n
class Cell:\n    def __init__(self, row, col, number, right_wall, bottom_wall):\n        self.row = row\n        self.col = col\n        self.number = number    # defines which set this block is in\n        self.right_wall = right_wall\n        self.bottom_wall= bottom_wall\n\n# every block includes 5x5 px white space + 1px on it\'s left and 1px on it\'s bottom for walls (if the block has ones)\ndef create_block(row, col, right_wall, bottom_wall):\n    for i in range(row-2, row+4):   # since the path is 5px wide\n        for j in range(col-2, col+4): …
Run Code Online (Sandbox Code Playgroud)

python maze python-3.x

5
推荐指数
1
解决办法
1081
查看次数

如果不一个接一个地更改重复列表项,请更改它们

我有一个重复的整数列表.例:

37 1 30 38 5 39 5 5 5 40 33 5 35 42 25 36 27 27 43 27

我需要将重复的数字更改为其他数字,如果它们不是一个接一个地去.新数字不应与列表中的其他数字重复.例如,上面的列表应该是这样的:

37 1 30 38 5 39 8 8 8 40 33 2 35 42 25 36 27 27 43 55

这就是我得到的:

a = [37, 1, 30, 38, 5, 39, 5, 5, 5, 40, 33, 5, 35, 42, 25, 36, 27, 27, 43, 27]

duplicates = list(item for item, count in Counter(a).items() if count > 1)


for dup in …
Run Code Online (Sandbox Code Playgroud)

python python-3.x

5
推荐指数
1
解决办法
76
查看次数

放大图像(可能是像素化但不模糊)

我写了一个脚本来绘制一些图像,通常不大于 50x50px。然后我想在 Tkinter 窗口中显示该图像。但首先我需要放大图像,因为 30x30px 太小,用户无法看到我的脚本生成的每个像素。所以我写了这个:

multiplier = 4
image = np.full((height * multiplier, width * multiplier, 3), 0, dtype=np.uint8)

for r in range(height):
    for c in range(width):
        for i in range(multiplier):
            for j in range(multiplier):
                image[r * multiplier + i][c * multiplier + j] = original[r][c]
Run Code Online (Sandbox Code Playgroud)

PS original 的初始化方式和image 一样

我也试过:

调整大小((宽度*乘数,高度*乘数),Image.ANTIALIAS)

但这不是一种选择,因为它会使图像看起来模糊。那么更好的解决方案是什么?

示例图像: 在此处输入图片说明

python

2
推荐指数
1
解决办法
1263
查看次数

相对于它所处的语句的执行,time()衡量的是哪个时间点?

问题不在于算法或修复代码中的错误.我只想说清楚跟踪时间是如何工作的.例如,有一行:

x = my_func(4, 2) * time()
Run Code Online (Sandbox Code Playgroud)

该行以3.0秒运行,my_func(4, 2)需要0.5秒才能返回结果.

问题是time()何时开始跟踪时间?在3.0秒,线路运行时?或者在3.5,my_func(4,2)计算后?

python python-3.x

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

标签 统计

python ×4

python-3.x ×3

maze ×1