Whilst integrating an array of data, an axis error occured. What is the cause and solution of this error?


4 weeks ago


4 time


I have an array of data labelled y_1, for which I want to compute a definite integral of its square value, however an axis error occurs. I'm using scipy.trapz to integrate the array.

I tried to define the axis as zero, however an axis error stating that the 'axis 0 is out of bounds for array of dimension 0'

The code is below:

    hn = np.zeros(n)

    hn[0] = integrate.trapz(lambda t: y_1**2, 0, 0.3)
    hn[1] = integrate.trapz(lambda t: y_2**2, 0, 0.3)
    hn[2] = integrate.trapz(lambda t: y_5**2, 0, 0.3)
    hn[3] = integrate.trapz(lambda t: y_20**2, 0, 0.3)

The error is:

    AxisError: axis -1 is out of bounds for array of dimension 0

0 answers