I'm a newbie but I think it is very 'Nim' to make an iterator:
iterator columns*[T](mat: seq[seq[T]]): seq[T] =
var col = newSeq[T](mat.len)
for c in 0..
This works perfectly, thank you! I manages to simply transpose the matrix to
get what I wanted, but this makes your code snippet was very helpful.
This is for coding homework where we are not allowed to use external packages.
Otherwise yes I agree!
> If you want to work with matrices I advice you to work with a library like ...
... [Neo](https://github.com/unicredit/neo)
If you want to work with matrices I advice you to work with a library like
[Arraymancer](https://github.com/mratsim/Arraymancer) instead of doing it by
hand.
It will be [easier](https://mratsim.github.io/Arraymancer/tuto.slicing.html)
and more efficient.
This works, however I'm looking forward to see what others come up with.
let rows = @[@[2, 4, 1], @[2, 0, 2], @[1, 1, 2], @[0, 0, 0]]
for index in rows[0].low .. rows[0].high:
var column: seq[int]
for row in rows:
column.add(row[index])
echo("column = ", column)
I have this seq[seq[int]] object:
@[@[2, 4, 1], @[2, 0, 2], @[1, 1, 2], @[0, 0, 0]]
Run
I want to iterate over each column so that I can perform a function on the
entire column. So the output should be:
column = @[2, 2, 1, 0]
column = @[4, 0, 1, 0]