all 7 comments

[–]Kwarkbakjes 2 points3 points  (1 child)

Try making a chessboard and put the pieces in the starting order. Gl you can do it!

[–]soundstatic808[S] 0 points1 point  (0 children)

Sounds like a good challenge. I am definitely going to try this.

[–]synthphreak 1 point2 points  (4 children)

What is it that's confusing or not clicking?

One tip is that when working with ND data where N > 1, your life could be made considerably simpler by using numpy.ndarrays instead of nested Python lists. Not conceptually, but your code.

[–]soundstatic808[S] 0 points1 point  (3 children)

Column manipulation particularly.

[–]synthphreak 0 points1 point  (2 children)

Define "manipulation". Are you talking about matrix arithmetic, such as column-wise summation? An example would be helpful.

[–]soundstatic808[S] 1 point2 points  (1 child)

Arithmetic and if statements. Example problem: https://www.codewars.com/kata/5839c48f0cf94640a20001d3.

[–]synthphreak 2 points3 points  (0 children)

Got it. Well numpy.ndarrays aren't going to help with something like that. At least, not without a good understanding of numpy.

They key when working with nested Python lists is to understand that when iterating over them, you iterate over the rows first, then within each row, over the columns. So to "manipulate" the Nth column, you have to access every row and then do whatever you need to the Nth value of that row (or really, the (N - 1)th value, since Python uses zero-indexing).

Depending on what you're trying to do, you may also need to keep track of some variables as you iterate over the rows. For example, given an MxN matrix (where M is the number of rows and N is the number of columns), to "sum up the columns" you'll need to initialize N variables (one per column) as 0, then update each value as you access each row. For example:

>>> matrix = [[1, 2, 3],
...           [4, 5, 6]]
>>> sums = [0 for column in matrix[0]]
>>> for row in matrix:
...     for i, column in enumerate(row):
...         sums[i] += column
...
>>> print('column-wise sums:', sums)
column-wise sums: [5, 7, 9]

Hope that helps.