浮点()参数必须是字符串或数字,而不是“zip”。

13

在 Python 2.7 中运行时没有问题,但在 Python 3 中运行时出现错误。

这段代码需要做哪些更改呢?

import matplotlib as mpl
poly = mpl.path.Path(zip(listx,listy))

我收到的错误是

TypeError: float() argument must be a string or a number, not 'zip'
1个回答

20
这是因为在Python2中,zip()返回一个元组列表,而mpl.path.Path()可以很好地接受它们。但在Python3中,zip()返回一个迭代器,你必须消耗它。你应该能够做到类似这样的事情:
>>> poly = mpl.path.Path(list(zip(listx, listy)))

@bikuser 没问题。你可以通过接受我的答案(小复选框标记)来表示感激之情。 - msvalkon

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接