PDA

View Full Version : [SOLVED] create python tuple of arbitrary length



nbo10
December 21st, 2009, 12:37 AM
I want to create a tuple with an arbitrary length. I have the following code.

im = np.hstack((width,width))

I want to change the number of widths in the call to hstack. I might have (width,width,....width) with 100 widths. Is there a clever python trick I can use? Thanks

CptPicard
December 21st, 2009, 12:42 AM
>>> width = 4
>>> (width,) * 5
(4, 4, 4, 4, 4)

nbo10
December 21st, 2009, 12:45 AM
Thanks, worked like a charm.