我写了一个简单的函数
def rect(t):
field = np.zeros((len(t),3))
for i in range(len(t)):
if t[i] >=-10 and t[i] <=10:
field[i,1] = 1
else:
field[i,1] = 0
return field
并想整合它
from scipy import integrate
def S_elem(t):
return rect(t)[:,1]*integr
integrate.quad(S_elem, -10, 10)
我收到这个错误
TypeError: object of type 'float' has no len()
我知道我可能不会使用 numpy 数组,但我需要它用于其他目的。如何在不删除 numpy 数组类型的情况下执行集成?