2D matrix operation (subtraction)

2020-02-21 Thread Andre Pany via Digitalmars-d-learn
Hi, I have a 2D double array and I want to subtract from the first column a value, is this possible with matrix operation in D? ``` void main() { double[][] data = [[0.0, 1.4], [1.0, 5.2], [2.0, 0.8]]; // subtract -2.0 from the first column for every value // Expected output

Re: 2D matrix operation (subtraction)

2020-02-21 Thread Ali Çehreli via Digitalmars-d-learn
On 2/21/20 12:51 AM, Andre Pany wrote: Hi, I have a 2D double array and I want to subtract from the first column a value, is this possible with matrix operation in D? ``` void main() {     double[][] data = [[0.0, 1.4], [1.0, 5.2], [2.0, 0.8]];     // subtract -2.0 from the first column fo

Re: 2D matrix operation (subtraction)

2020-02-21 Thread Andre Pany via Digitalmars-d-learn
On Friday, 21 February 2020 at 11:53:02 UTC, Ali Çehreli wrote: On 2/21/20 12:51 AM, Andre Pany wrote: Hi, I have a 2D double array and I want to subtract from the first column a value, is this possible with matrix operation in D? ``` void main() {     double[][] data = [[0.0, 1.4], [1.0, 5

Re: 2D matrix operation (subtraction)

2020-02-21 Thread jmh530 via Digitalmars-d-learn
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.

Re: 2D matrix operation (subtraction)

2020-02-21 Thread jmh530 via Digitalmars-d-learn
On Friday, 21 February 2020 at 14:43:37 UTC, jmh530 wrote: [snip] Actually, I kind of prefer the relevant line as x.byDim!1[0].each!"a -= 2"; which makes it a little clearer that you can easily change [0] to [1] to apply each to the second column instead.

Re: 2D matrix operation (subtraction)

2020-02-21 Thread septc via Digitalmars-d-learn
On Friday, 21 February 2020 at 08:51:49 UTC, Andre Pany wrote: Hi, I have a 2D double array and I want to subtract from the first column a value, is this possible with matrix operation in D? ``` void main() { double[][] data = [[0.0, 1.4], [1.0, 5.2], [2.0, 0.8]]; // subtract -2.0 fr

Re: 2D matrix operation (subtraction)

2020-02-22 Thread 9il via Digitalmars-d-learn
On Friday, 21 February 2020 at 13:42:24 UTC, Andre Pany wrote: Mir is great and actually I try to rewrite some Python Pandas Dataframe index logic. Maybe mir.series [1] can work for you. Series!(Key*, Value*) - is a pair of two 1D ndslices, they can be sorted according to the first one ndslic

Re: 2D matrix operation (subtraction)

2020-02-22 Thread Andre Pany via Digitalmars-d-learn
On Saturday, 22 February 2020 at 08:29:32 UTC, 9il wrote: On Friday, 21 February 2020 at 13:42:24 UTC, Andre Pany wrote: Mir is great and actually I try to rewrite some Python Pandas Dataframe index logic. Maybe mir.series [1] can work for you. Series!(Key*, Value*) - is a pair of two 1D ndsl

Re: 2D matrix operation (subtraction)

2020-02-25 Thread jmh530 via Digitalmars-d-learn
On Saturday, 22 February 2020 at 08:29:32 UTC, 9il wrote: [snip] Maybe mir.series [1] can work for you. I had a few other thoughts after looking at septc's solution of using y[0..$, 0] *= 100; to do the calculation. 1) There is probably scope for an additional select function to handle the