你能帮我解决这个问题吗?循环浮动范围
代码: -
import numpy as np
def test(numList):
yesList=[]
for num in numList:
print num, "start here"
for i in np.arange(2.0,3.0,0.1):
print i
if num==i: yesList.append(num)
return yesList
print test([2.1,2.3,3.0])
输出: -
2.1 start here
2.0
2.1
2.2
2.3
2.4
2.5
2.6
2.7
2.8
2.9
2.3 start here
2.0
2.1
2.2
2.3
2.4
2.5
2.6
2.7
2.8
2.9
3.0 start here
2.0
2.1
2.2
2.3
2.4
2.5
2.6
2.7
2.8
2.9
[2.1]
我希望它打印[2.1,2.3]
但它只是给我[2.1]
,如图所示。
看起来你已经发现了你的标记已经存在的问题 - 浮点。 – irrelephant 2012-08-13 05:56:15
你的格式最初是不正确的(该函数不会编译),所以我必须根据你的示例输出来猜测你的意思。如果我猜错了,请纠正它。 – Gabe 2012-08-13 05:59:58