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

Refresh

4 weeks ago

Views

4 time

0

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:

    n=4
    hn = np.zeros(n)

    ```
    #n=1
    hn[0] = integrate.trapz(lambda t: y_1**2, 0, 0.3)
    ```
    #n=2
    hn[1] = integrate.trapz(lambda t: y_2**2, 0, 0.3)
    #n=5
    hn[2] = integrate.trapz(lambda t: y_5**2, 0, 0.3)
    #n=20
    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