gradient

Function gradient 

Source
pub fn gradient<T>(
    array: ArrayView<'_, T, Ix2>,
    spacing: Option<(T, T)>,
) -> GradientResult<T>
where T: Clone + Float,
Expand description

Calculate the gradient of an array

§Arguments

  • array - The input 2D array
  • spacing - Optional tuple of spacings for each axis

§Returns

A tuple of arrays (grad_y, grad_x) containing the gradient along each axis

§Examples

use ndarray::array;
use scirs2_core::ndarray_ext::manipulation::gradient;

let a = array![[1.0, 2.0, 3.0], [4.0, 5.0, 6.0]];

// Calculate gradient with default spacing
let (grad_y, grad_x) = gradient(a.view(), None).unwrap();
// Vertical gradient (y-direction)
assert_eq!(grad_y.shape(), &[2, 3]);
// Horizontal gradient (x-direction)
assert_eq!(grad_x.shape(), &[2, 3]);