How do you map_inplace or par_map_inplace in an ndarray while using the index of the current element you're mapping over?
array.map_inplace(|val| {
*val = (expression involving the index)
})
You can keep track of a global counter for the non-parallel version, but this won't work for the parallel version.
For a non-parallel in-place mutation with index, you can use
.indexed_iter_mut()like so:For a parallel version, you would need to use rayon's
.par_bridge()sinceIndexedIterMutisn't inherently a parallel iterator (ndarray uses rayon internally for parallelization):