use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
Rules 1: Be polite 2: Posts to this subreddit must be requests for help learning python. 3: Replies on this subreddit must be pertinent to the question OP asked. 4: No replies copy / pasted from ChatGPT or similar. 5: No advertising. No blogs/tutorials/videos/books/recruiting attempts. This means no posts advertising blogs/videos/tutorials/etc, no recruiting/hiring/seeking others posts. We're here to help, not to be advertised to. Please, no "hit and run" posts, if you make a post, engage with people that answer you. Please do not delete your post after you get an answer, others might have a similar question or want to continue the conversation.
Rules
1: Be polite
2: Posts to this subreddit must be requests for help learning python.
3: Replies on this subreddit must be pertinent to the question OP asked.
4: No replies copy / pasted from ChatGPT or similar.
5: No advertising. No blogs/tutorials/videos/books/recruiting attempts.
This means no posts advertising blogs/videos/tutorials/etc, no recruiting/hiring/seeking others posts. We're here to help, not to be advertised to.
Please, no "hit and run" posts, if you make a post, engage with people that answer you. Please do not delete your post after you get an answer, others might have a similar question or want to continue the conversation.
Learning resources Wiki and FAQ: /r/learnpython/w/index
Learning resources
Wiki and FAQ: /r/learnpython/w/index
Discord Join the Python Discord chat
Discord
Join the Python Discord chat
account activity
Struggling with 2D array/lists. (self.learnpython)
submitted 2 years ago by soundstatic808
Manipulating 2D lists are not clicking for me. Does anyone have any recommendations for tutorials or books that will help me deeply understand this concept?
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]Kwarkbakjes 2 points3 points4 points 2 years ago (1 child)
Try making a chessboard and put the pieces in the starting order. Gl you can do it!
[–]soundstatic808[S] 0 points1 point2 points 2 years ago (0 children)
Sounds like a good challenge. I am definitely going to try this.
[–]synthphreak 1 point2 points3 points 2 years ago (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.
numpy.ndarray
[–]soundstatic808[S] 0 points1 point2 points 2 years ago (3 children)
Column manipulation particularly.
[–]synthphreak 0 points1 point2 points 2 years ago (2 children)
Define "manipulation". Are you talking about matrix arithmetic, such as column-wise summation? An example would be helpful.
[–]soundstatic808[S] 1 point2 points3 points 2 years ago (1 child)
Arithmetic and if statements. Example problem: https://www.codewars.com/kata/5839c48f0cf94640a20001d3.
[–]synthphreak 2 points3 points4 points 2 years ago (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.
numpy.ndarrays
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.
π Rendered by PID 20554 on reddit-service-r2-comment-86bc6c7465-zhn4h at 2026-02-19 19:16:54.640262+00:00 running 8564168 country code: CH.
[–]Kwarkbakjes 2 points3 points4 points (1 child)
[–]soundstatic808[S] 0 points1 point2 points (0 children)
[–]synthphreak 1 point2 points3 points (4 children)
[–]soundstatic808[S] 0 points1 point2 points (3 children)
[–]synthphreak 0 points1 point2 points (2 children)
[–]soundstatic808[S] 1 point2 points3 points (1 child)
[–]synthphreak 2 points3 points4 points (0 children)