
On Tue, Apr 5, 2011 at 1:02 PM, Christopher Barker <Chris.Barker@noaa.gov> wrote:
HI folks,
What's the fastest way to convert a numpy array to tuples?
Unfortunately, not all packages take arbitrary sequences when they are expecting a list of tuples. In this case, I'm using PIL's ImageDraw, and want to do:
draw.line(points)
(points is an Nx2 numpy array of ints)
but if I pass in an array, I get, oddly enough, nothing. NO error, just nothing drawn.
if I do:
draw.line(points.tolist())
SystemError: new style getargs format but argument is not a tuple
So I seem to need tuples. This works:
draw.line([tuple(p) for p in points.tolist()])
but that seems like it would be slower than it should be (to be honest, not profiled).
Is there a faster way?
Maybe numpy should have a ndarray.totuple() method.
does a structured dtype work? Josef
-Chris
-- Christopher Barker, Ph.D. Oceanographer
Emergency Response Division NOAA/NOS/OR&R (206) 526-6959 voice 7600 Sand Point Way NE (206) 526-6329 fax Seattle, WA 98115 (206) 526-6317 main reception
Chris.Barker@noaa.gov _______________________________________________ NumPy-Discussion mailing list NumPy-Discussion@scipy.org http://mail.scipy.org/mailman/listinfo/numpy-discussion