Skip to main content

fromfunction

Function fromfunction 

Source
pub fn fromfunction<T, D, F>(shape: D, f: F) -> FerrayResult<Array<T, D>>
where T: Element, D: Dimension, F: FnMut(&[usize]) -> T,
Expand description

Construct an array by executing a function over each coordinate.

f is called with the multi-index of each element (as &[usize]) and returns the value to place there. Iteration is C-order over the given shape.

Analogous to numpy.fromfunction(func, shape, ...). NumPy passes per-axis index arrays to func (broadcasting); ferray instead invokes f per element with a coordinate slice — equivalent in result for scalar-returning functions but simpler in Rust.