在Python 3里,reduce()函数已经被从全局名字空间里移除了,它现在被放置在fucntools模块里 用的话要 先引入 from functools import reduce
import numpy
as np
from functools
import reduce
#from functools import
def prod(x
, y):
return x*y
print(reduce(prod
, [
2, 4, 5, 7, 12]))
为什么没有输出呢?
转载请注明原文地址: https://www.6miu.com/read-61259.html