mir - Help on how to transform multidimentional arrays.
jmh530
john.michael.hall at gmail.com
Thu Apr 29 15:56:48 UTC 2021
On Thursday, 29 April 2021 at 15:26:15 UTC, Newbie wrote:
> [snip]
>
> Forgot to add the the first array was created using the
> following code.
> auto base = iota(2, 5, 3);
What you're basically asking for the first one is to convert for
row major to column major. There doesn't seem to be a specific
function for that, but you can piece it together. The second one
is just applying allReversed to the result of that. So we have:
```d
/+dub.sdl:
dependency "mir-algorithm" version="~>3.10.25"
+/
import std.stdio: writeln;
import mir.ndslice.topology: iota, flattened, reshape, universal;
import mir.ndslice.dynamic: transposed, allReversed;
void main() {
auto x = iota(2, 5, 3);
int err;
auto y = x.flattened.reshape([3, 5, 2], err).transposed!(1,
2);
auto z = y.allReversed;
writeln(x);
writeln(y);
writeln(z);
}
```
More information about the Digitalmars-d-learn
mailing list