Say I have a numpy matrix like so:
[[ x1, x2, x3, ... ],
[ y1, y2, y3, ... ],
[ z1, z2, z3, ... ],
[ 1, 1, 1, ... ]]
From which I want to extract a list of lists like so:
[[x1, y1, z1], [x2, y2, z2], [x3, y3, z3], ... ]
What is the most optimal way of doing this?
At the moment I have:
tpoints = [pt[:3].tolist() for pt in numpy.asarray(tptmat.T)]
And the call to tolist()
is taking up disproportionate amount of time, approximately a third of the time spent in the most time consuming function of my program.
ncalls tottime percall cumtime percall filename:lineno(function)
14422540 69.777 0.000 69.777 0.000 {method 'tolist' of 'numpy.ndarray' objects}
20 64.258 3.213 178.057 8.903 trans.py:152(_apply)
...