0

I have an array of object with size (22, 2) for Y axis, and the corresponding x-axis is an array of object with size (22, 2) as well. I need to calculate the Area between the curve y = f(x), and the x-axis, for each array. I wrote this code:

Area = np.trapz(y,x)

I got an array of object in which each module consists of many elements, but I expected to get a single value (area) for each y=f(x).

How can I calculate correctly the area for each function f(x) stored in the array of object?

Krystal
  • 31
  • 5
  • Related: https://stackoverflow.com/questions/13320262/calculating-the-area-under-a-curve-given-a-set-of-coordinates-without-knowing-t – Thaer A Apr 29 '20 at 10:59
  • The input arrays are 2-dimensional (size (22, 2)). To get a scalar output from `trapz` your inputs will have to be 1-dimensional arrays. Is it possible that one of your input arrays contains both `x` and `y` in its columns? – AbbeGijly Apr 29 '20 at 11:02
  • the 2-dimensional input arrays (22,2) consists of two columns: the first column is `[0, 1, 2, 3, ...]` and it's just an index column; whareas in the second column, each element contains an array (corresponding to Y). To overcome the problem you said, I selected the second column only, andt it works now! Thank you. `Area_t=np.trapz(X[1,:],Y[1,:])` Then, I compared that results with that coming from `scipy.integrate` and I have the same values. – Krystal Apr 29 '20 at 11:45

0 Answers0