请问您需要解释Numpy中vectorize函数的excluded参数吗?简单来说,excluded参数用于指定哪些输入参数不应传递给向量化函数。这可以帮助您在处理多个数组时只使用特定的输入参数。
import numpy as np
vc = np.vectorize(np.mod)
print(vc([5,11,7,4],2)) # first element will be iterated
print(vc([5,11,7,4],[2,3,4,5])) # both elements will be iterated
print(vc(5,[2,3,4,5])) # only second element will be iterated
p
的函数 g(x,p)
(例如:查找表或多项式参数)。因此,p
必须保持为数组,否则该函数将产生错误或错误数据。这是通过排除 p
实现的。请注意,使用 exclude,现在必须命名所有参数。例如:import numpy as np
def g(x,p):
return p[0]+x*p[1]+x*x*p[2]
print(g(5,[0,0,1]))
vg = np.vectorize(g, excluded=['p'])
print(vg(x=[0,1,2,3,4,5],p=[0,0,1])) # p will not be iterated
numpy
的初学者。我认为你不应该花太多时间学习np.vectorize
。我回答了一些涉及到这个excluded
参数的问题,但如果没有清晰的了解你的知识水平或需求,解释它可能不值得我们的时间。 - hpaulj