I am trying to create a function, which returns a vector and then integrating it element by element. This is what I have so far
def int1(b):
j = 1
for q in range(0,len(alpha)):
j = j + alpha[q]*(b**q)
p = np.exp(-j);
inu = np.zeros(len(alpha))
for q in range(0,len(alpha)):
inu[q] = np.exp(-j)*(b**q)
return inu
This works if I type something like
print int1(0.1)[2]
However
print sp.integrate.quad(int1(b)[2], 1e-16, 1, epsrel=1e-20)[0]
does not work, or any reasonable variant I can think of. How can I get it to work? either i get TypeError: 'function' object has no attribute 'getitem' if i leave out the b or ValueError: invalid callable given if I have it in.
int1(b)[2]
work since you onlyreturn
a single value? If you returned multiple results, then you're indexing a particular result. If you return a single string, well you're picking a character in that string, and so on... – roganjosh Jan 8 '18 at 22:39