0

The link below contains some python script; what is the purpose of “chan” when flattening the list?

pixels = [chan for px in pixels for chan in px]

Link with script

Duarte Farrajota Ramos
  • 59,425
  • 39
  • 130
  • 187
Coffeecup
  • 1
  • 1
  • 1
    It's an iterator used in a list comprehension. https://realpython.com/list-comprehension-python/ – Markus von Broady Feb 13 '22 at 19:59
  • 1
    The best place to ask your question would be in a comment to the linked question... So I answered it there. The line is an equivalent to pixels = [] \n for chan in px: \n\t for px in pixels: \n\t\t pixels.append(px) where \n and \t mean a newline and a tab. – Markus von Broady Feb 13 '22 at 20:04
  • I really don't understand why it's possible at all to chain list comprehensions in python... It's so hard to make sense. A bunch of for loops are really easier to understand imo. anyways it stands for channel since it's a loop that flattens the pixels of an image. But this is not the right place to ask this question, as mentioned in other comments. cheers – Gorgious Feb 13 '22 at 20:57
  • Hello and welcome. While files, images, and external videos or links may be helpful additions they should not be the only way to obtain information about your issue. Don't make understanding your question rely on downloading a file, watching a video or visiting an external site. Use the builtin tools to upload images or gifs, along with thoroughly explaining the problem in written form so it can be indexed and searched for thus helping future visitors with similar issues. – Duarte Farrajota Ramos Feb 13 '22 at 23:13

1 Answers1

1

It's the 'channel': red, green, and blue. Each pixel's colour consists of a value for each channel.

dr. Sybren
  • 7,139
  • 1
  • 23
  • 52
  • Due to a lack of reputation points I was not allowed to comment on the original post. The instructions given were to post a question with a link to the original post.

    Please clarify how my question was incorrect.

    Thank you for the answers!

    – Coffeecup Feb 14 '22 at 01:59
  • @Coffeecup I didn't know (or didn't remember) such limit exists. Still, your question seems to be a Python question, at least the way I understood it. – Markus von Broady Feb 14 '22 at 09:25