np.gradient does not accept coordinate array

Hi,

I’m trying usenp.gradient to calculate the derivative of an irregularly spaced array.

I’d like to do something along the lines of:

import dask.array

f = dask.array.range(50)
x = dask.array.range(50)

f_prime = np.gradient(f, x)

but a NotImplementedError is raised:

---------------------------------------------------------------------------
NotImplementedError                       Traceback (most recent call last)
Cell In [14], line 1
----> 1 dask.array.gradient(f, x, axis=-1)

File ~/mambaforge/envs/thermal/lib/python3.9/site-packages/dask/array/routines.py:706, in gradient(f, axis, *varargs, **kwargs)
    704 else:
    705     if isinstance(varargs[i], Array):
--> 706         raise NotImplementedError("dask array coordinated is not supported.")
    707     # coordinate position for each block taking overlap into account
    708     chunk = np.array(f.chunks[ax])

NotImplementedError: dask array coordinated is not supported.

I’m kind of confused since there’s no error raised by x being an array, and according to the dask.array.gradient documentation this type of operation is supported.

Is this not the case?

Thanks!

I’m kind of confused since there’s no error raised by x being an array, and according to the dask.array.gradient documentation this type of operation is supported.

Supplying coordinates to da.gradient is not supported by dask.array as the error message states. The documentation indeed says otherwise but that’s because the docstring was copied from numpy.gradient…