下面是我将一个整数元组重缩放到另一个整数元组的步骤。有更好的办法吗?你知道吗
size_tup = tuple([int(round(s*shrink)) for s in size])
我需要使用Image
模块调整图像大小,因为这需要tuple
的ints
。举个例子,如果我想把一个图像的大小调整50%,我会这样做
size = .5
size_tup = tuple([int(round(s*shrink)) for s in size])
im = im.resize(size_tup, Image.ANTIALIAS)
所以我只处理长度为2的元组。我最关心的是代码的简单性,因为上面的内容似乎有些过分了。你知道吗
我想类似的东西会对你有帮助。你知道吗
根据map函数的定义:
在代码中,您将创建一个列表,然后将其转换为元组。使用map函数来延迟列表的计算(在python3中)。你知道吗
根据注释,您也可以这样做(删除
[]
):相关问题 更多 >
编程相关推荐