0

I am trying to calculate a value of function f_integ, which is a result of integration of function f from 0 to x_v.

   f = lambda x : x + 1

    def f_integ(x_array):
        int_result = np.zeros_like(x_array)
        indexes = np.shape(x_array)[0]
        for ind in range(indexes):
            x_v = x_array[ind]
            int_result[ind] = integ.quad(f, 0.0, x_v)[0]
        return int_result

    C = f_integ(1)
    print "C", C

When I run this, I get the following error:

Traceback (most recent call last):
  File "untitled.py", line 117, in <module>
    C = f_integ(1)
  File "scr1.py", line 110, in f_integ
    indexes = np.shape(x_array)[0]
IndexError: tuple index out of range

I know that quad() returns a tuple, but I can not figure out how to put a number as an argument in the result of integration. I'm new to Python, please help.

ani87
  • 17
  • 5

1 Answers1

1

Call the function like this:

C = f_integ(np.array([1]))
print "C", C

Currently you are passing a number to f_integ(), not an array. When it encounters np.shape(x_array)[0], the shape of a number is just (), so it cannot return anything at index 0 for an empty tuple.

Antimony
  • 2,230
  • 3
  • 28
  • 38