2D matrix operation (subtraction)

jmh530 john.michael.hall at gmail.com
Fri Feb 21 14:43:37 UTC 2020


On Friday, 21 February 2020 at 11:53:02 UTC, Ali Çehreli wrote:
> [snip]
> auto byColumn(R)(R range, size_t n) {
>   return Column!R(range, n);
> }

mir has byDim for something similar (numir also has alongDim).

This is how you would do it:

import mir.ndslice;

void main() {
     auto x = [0.0, 1.4, 1.0, 5.2, 2.0, 0.8].sliced(3, 2);
     x.byDim!1.front.each!"a -= 2";
}

My recollection is that it is a little bit trickier if you want 
to subtract a vector from each column of a matrix (the sweep 
function in R).


More information about the Digitalmars-d-learn mailing list