replace deepest level of nested list
Michael Spencer
mahs at telcopartners.com
Tue Sep 5 20:23:14 EDT 2006
David Isaac wrote:
> Thanks to both Roberto and George.
> I had considered the recursive solution
> but was worried about its efficiency.
> I had not seen how to implement the numpy
> solution, which looks pretty nice.
>
> Thanks!
> Alan
>
>
You could also use pyarray, which mimics numpy's indexing, but uses native
python lists as the data store.
So...
>>> from pyarray import ndlist
>>> source =
ndlist([[['r00','g00','b00'],['r01','g01','b01']],[['r10','g10','b10'],['r11','g11'
... ,'b11']]])
>>> source
array([[[r00, g00, b00],
[r01, g01, b01]],
[[r10, g10, b10],
[r11, g11, b11]]])
>>> source[...,0] # note elipsis means skip all but the last dimension
array([[r00, r01],
[r10, r11]])
>>> _.tolist()
[['r00', 'r01'], ['r10', 'r11']]
>>>
pyarray (single pure-python module) can be downloaded from:
http://svn.brownspencer.com/pyarray/trunk/
Regards
Michael
More information about the Python-list
mailing list