absolute newbie: divide a list into sublists (nested lists?) of fixed length
ergconcepts at googlemail.com
ergconcepts at googlemail.com
Sat Apr 11 16:14:20 EDT 2009
Hi,
I have a list looking like
[ 0.84971586, 0.05786009, 0.9645675, 0.84971586, 0.05786009,
0.9645675, 0.84971586, 0.05786009, 0.9645675, 0.84971586,
0.05786009, 0.9645675]
and I would like to break this list into subsets of fixed length (say,
three elements), i.e. to convert the list into a form such as the one
generated by the following example code which I have found:
>>>import numpy
>>>s = numpy.random.random((3,3))
>>>s
array([[ 0.11916176, 0.96409475, 0.72602155],
[ 0.84971586, 0.05786009, 0.96456754],
[ 0.81617437, 0.845342 , 0.09109779]])
How can I create such a 2d array (i.e., something like a symmetric
matrix) from my data?
Thanks in advance,
Bernard
PS: Note that the numpy import is not important here, it is just the
structure of the data that matters..
More information about the Python-list
mailing list