[PYTHON MATRIX-SIG] Nested list representation of an array
Konrad Hinsen
hinsen@ibs.ibs.fr
Mon, 28 Oct 96 13:56:18 GMT
Does anyone know an efficient way to obtain a nested list
representation of an array? list() will handle only the first
axis. The best I can come up with is a recursive definition:
def nested_list(a):
if len(a.shape) < 2:
return list(a)
else:
return map(nested_list, a)
I don't want to know how long this takes for a large rank-10 array...
Konrad.
--
-------------------------------------------------------------------------------
Konrad Hinsen | E-Mail: hinsen@ibs.ibs.fr
Laboratoire de Dynamique Moleculaire | Tel.: +33-76.88.99.28
Institut de Biologie Structurale | Fax: +33-76.88.54.94
41, av. des Martyrs | Deutsch/Esperanto/English/
38027 Grenoble Cedex 1, France | Nederlands/Francais
-------------------------------------------------------------------------------
=================
MATRIX-SIG - SIG on Matrix Math for Python
send messages to: matrix-sig@python.org
administrivia to: matrix-sig-request@python.org
=================