Last active
July 25, 2021 18:07
-
-
Save joshuaskelly/fa057cf68dcb7a3177d7c0a011090034 to your computer and use it in GitHub Desktop.
Example of Unstructuring and Structuring Pixel Data Using Python
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Flattening a sequence of structured data | |
image = ((1, 1, 1), (2, 2, 2), (3, 3, 3), (4, 4, 4)) | |
[rgb for pixel in image for rgb in pixel] | |
# >>> [1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 4] | |
# Structuring a sequence of flat data | |
image = (1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 4) | |
it = iter(image) | |
tuple(zip(it, it, it)) | |
# >>> ((1, 1, 1), (2, 2, 2), (3, 3, 3), (4, 4, 4)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment