unhappy_mage
[H]ard|DCer of the Month - October 2005
- Joined
- Jun 29, 2004
- Messages
- 11,455
I've got a program that is giving me back a nested list of the following form:
[[[3, 4], [5, 6]], [[7, 8], [9, 0]], [[a, b], [c d]]]
but to output the list I need to restructure it to have the following form:
[[3, 4], [5, 6], [7, 8], [9, 0], [a, b], [c, d]]
The innermost groups are what I need; I don't need things flattened all the way. What's a good way to do this?
For those interested in the application:
I've written a raytracer in Python, and I'm in the process of multithreading it using MPI. I farm out the actual ray shooting: each process makes a local array of pixels like [[3, 4], [5, 6]], and then I collect those local arrays onto one process (and obtain something like the first example list). I don't control the collection algorithm, it just takes a bunch of elements (which happen to be lists) and makes a list out of them. Then I need to write an output image file (using a list-of-lists with exactly 2 dimensions), and while I could mess with my output function to handle weirdly shaped lists, I'd rather feed it the right input than complicate it unnecessarily.
So, any ideas?
[[[3, 4], [5, 6]], [[7, 8], [9, 0]], [[a, b], [c d]]]
but to output the list I need to restructure it to have the following form:
[[3, 4], [5, 6], [7, 8], [9, 0], [a, b], [c, d]]
The innermost groups are what I need; I don't need things flattened all the way. What's a good way to do this?
For those interested in the application:
I've written a raytracer in Python, and I'm in the process of multithreading it using MPI. I farm out the actual ray shooting: each process makes a local array of pixels like [[3, 4], [5, 6]], and then I collect those local arrays onto one process (and obtain something like the first example list). I don't control the collection algorithm, it just takes a bunch of elements (which happen to be lists) and makes a list out of them. Then I need to write an output image file (using a list-of-lists with exactly 2 dimensions), and while I could mess with my output function to handle weirdly shaped lists, I'd rather feed it the right input than complicate it unnecessarily.
So, any ideas?