generating points on a grid - efficiently
Rajarshi Guha
rajarshi at presidency.com
Sat Mar 6 14:42:54 EST 2004
On Sat, 06 Mar 2004 18:44:47 +0000, simon place wrote:
> Rajarshi Guha wrote:
>> Hi,
>> I've written some code that takes a N lists of numbers (corresponding to
>> axes) and generates a list of grid points (N dimensional grid) for the
>> supplied axes. So as an example say my two axes are defined as
>>
>> v1 = [1,2,3]
>> v2 = [1,2,3]
>>
>> My code will return to me a list of points:
>>
>> (1,1), (1,2), (1,3) ....(3,1), (3,2), (3,3)
>>
>
> [[a,b] for a in v1 for b in v2]
>
>
>> and so on. For 3 axes, I would obtain 27 points and so on.
>> I've included the code below.
>
>
> [[a,b,c] for a in v1 for b in v2 for c in v3]
>
Thanks very much - it speeded it up significantly
More information about the Python-list
mailing list