[Numpy-discussion] differencing numarray arrays.
Robert Kern
rkern at ucsd.edu
Tue Jul 13 13:01:04 EDT 2004
Mike Zingale wrote:
> Hi, I am trying to efficiently compute a difference of two 2-d flux
> arrays, as arises quite commonly in finite-difference/finite-volume
> methods. Ex:
>
> a = arange(64)
> a.shape = (8,8)
>
> I want to do create a new array, b, of shape such that
>
> b[i,j] = a[i,j] - a[i-1,j]
>
> for 1 <= i < 8
> 0 <= i < 8
Try
b = a[1:] - a[:-1]
--
Robert Kern
rkern at ucsd.edu
"In the fields of hell where the grass grows high
Are the graves of dreams allowed to die."
-- Richard Harter
More information about the NumPy-Discussion
mailing list