Nadav Horesh wrote: > Here is what I get with the orriginal trapz function: > > IDLE 1.2.2 >>>> import numpy as np >>>> np.__version__ > '1.1.0' >>>> y = np.arange(24).reshape(6,4) >>>> x = np.arange(6) >>>> np.trapz(y, x, axis=0) > > Traceback (most recent call last): > File "<pyshell#4>", line 1, in <module> > np.trapz(y, x, axis=0) > File "C:\Python25\Lib\site-packages\numpy\lib\function_base.py", line 1536, > in trapz > return add.reduce(d * (y[slice1]+y[slice2])/2.0,axis) > ValueError: shape mismatch: objects cannot be broadcast to a single shape > (Try not to top post on this list.)
I can get it to work like this: import numpy as np y = np.arange(24).reshape(6,4) x = np.arange(6).reshape(-1,1) np.trapz(y, x, axis=0) From the text of the error message, you can see this is a problem with broadcasting. Due to broadcasting rules (which will *prepend* dimensions with size 1), you need to manually add an extra dimension to the end. Once I resize x, I can get this to work. You might want to look at this: http://www.scipy.org/EricsBroadcastingDoc Ryan -- Ryan May Graduate Research Assistant School of Meteorology University of Oklahoma _______________________________________________ Numpy-discussion mailing list Numpy-discussion@scipy.org http://projects.scipy.org/mailman/listinfo/numpy-discussion