Pretty-printing D arrays with Mir
tastyminerals
tastyminerals at gmail.com
Sun May 31 22:40:09 UTC 2020
I often print arrays to see how they look and their contents.
NumPy has a nice way of pretty-printing the arrays, and I was
lacking this in D.
For the sake of practice, I wrote a small package. It uses
mir.ndslice but works for both standard D arrays and Mir Slices.
import pretty_array;
import mir.ndslice;
import std.stdio;
void main() {
auto b = [2, 2, 6].iota!int(1).fuse;
b.prettyArr.writeln;
}
┌ ┐
│┌ ┐│
││ 1 2 3 4 5 6││
││ 7 8 9 10 11 12││
│└ ┘│
│┌ ┐│
││13 14 15 16 17 18││
││19 20 21 22 23 24││
│└ ┘│
└ ┘
https://github.com/tastyminerals/pretty_d_array
There are of course a couple of things to finish like floating
precision and small number suppression.
Still, hope somebody will find it handy.
More information about the Digitalmars-d-announce
mailing list