Function to compute 3D gradient with unevenly spaced sample locations

不羁岁月 提交于 2019-12-04 17:04:06

Two things to note: First, scalars are single values, not arrays. Second, the signature of the function is numpy.gradient(f, *varargs, **kwargs). Note the * before varargs. That means if varargs is a list, you pass *varargs. Or you can just provide the elements of varargs as separate arguments.

So, np.gradient wants a single value for the distance along each dimension, like:

np.gradient(tt, np.diff(x)[0], np.diff(y)[0], np.diff(z)[0])

or:

distances = [np.diff(x)[0], np.diff(y)[0], np.diff(z)[0]]
np.gradient(tt, *distances)

The required dx ... to be passed to np.gradient aren't grids of differences, but just one scalar each. So grad = np.gradient(tt,0.1,0.1,0.1)appears to work.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!