Re: How to iterate over a seq[seq[int]] to keep only columns?

2019-01-14 Thread lux
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..

Re: How to iterate over a seq[seq[int]] to keep only columns?

2019-01-13 Thread cag104
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.

Re: How to iterate over a seq[seq[int]] to keep only columns?

2019-01-13 Thread cag104
This is for coding homework where we are not allowed to use external packages. Otherwise yes I agree!

Re: How to iterate over a seq[seq[int]] to keep only columns?

2019-01-13 Thread miran
> If you want to work with matrices I advice you to work with a library like ... ... [Neo](https://github.com/unicredit/neo)

Re: How to iterate over a seq[seq[int]] to keep only columns?

2019-01-13 Thread BigEpsilon
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.

Re: How to iterate over a seq[seq[int]] to keep only columns?

2019-01-13 Thread Stromberg
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)

How to iterate over a seq[seq[int]] to keep only columns?

2019-01-13 Thread cag104
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]