summaryrefslogtreecommitdiff
path: root/numpy/lib/utils.py
diff options
context:
space:
mode:
authordanieljfarrell <danieljfarrel@me.com>2013-08-12 14:33:11 +0900
committerCharles Harris <charlesr.harris@gmail.com>2013-09-07 11:55:24 -0600
commit332d628744a0670234585053dbe32a3e82e0c4db (patch)
tree65ccff2c4c8bed74ad0413a6d536a1b20ed120fa /numpy/lib/utils.py
parent1ec94198399e91baf562799548c443040532cd0b (diff)
downloadnumpy-332d628744a0670234585053dbe32a3e82e0c4db.tar.gz
ENH: Improve accuracy of numpy.gradient at edges
* numpy.gradient has been enhanced to use a second order accurate one-sided finite difference stencil at boundary elements of the array. Second order accurate central difference are still used for the interior elements. The result is a fully second order accurate approximation of the gradient over the full domain. * The one-sided stencil uses 3 elements each with a different weight. A forward difference is used for the first element, dy/dx ~ -(3.0*y[0] - 4.0*y[1] + y[2]) / (2.0*dx) and backwards difference is used for the last element, dy/dx ~ (3.0*y[-1] - 4.0*y[-2] + y[-3]) / (2.0*dx) * Because the datetime64 datatype cannot be multiplied a view is taken of datetime64 arrays and cast to int64. The gradient algorithm is then applied to the view rather than the input array. * Previously no dimension checks were performed on the input array. Now if the array size along the differentiation axis is less than 2, a ValueError is raised which explains that more elements are needed. If the size is exactly two the function falls back to using a 2 point stencil (the old behaviour). If the size is 3 and above then the higher accuracy methods are used. * A new test has been added which validates the higher accuracy. Old tests have been updated to pass. Note, this should be expected because the boundary elements now return different (more accurate) values.
Diffstat (limited to 'numpy/lib/utils.py')
0 files changed, 0 insertions, 0 deletions