[Numpy-discussion] How do I use numpy to do this?
Rob Hooft
rob at hooft.net
Fri Jun 2 00:31:27 CDT 2006
Christopher Barker wrote:
> x = N.arange(minx, maxx+Spacing, Spacing) # makeing sure to get the last
> point
> y = N.arange(miny, maxy+Spacing, Spacing) # an extra is OK
> points = N.zeros((len(y), len(x), 2), N.Float)
> x.shape = (1,-1)
> y.shape = (-1,1)
> points[:,:,0] += x
> points[:,:,1] += y
> points.shape = (-1,2)
>
> print points
How about something like:
>>> k=Numeric.repeat(range(0,5+1),Numeric.ones(6)*7)
>>> l=Numeric.resize(range(0,6+1),[42])
>>>
zone=Numeric.concatenate((k[:,Numeric.NewAxis],l[:,Numeric.NewAxis]),axis=1)
>>> zone
array([[0, 0],
[0, 1],
[0, 2],
...
[5, 4],
[5, 5],
[5, 6]])
This is the same speed as Robert Kern's solution for large arrays, a bit
slower for small arrays. Both are a little faster than yours.
Rob
--
Rob W.W. Hooft || rob at hooft.net || http://www.hooft.net/people/rob/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: timer.py
Type: text/x-python
Size: 1244 bytes
Desc: not available
Url : http://projects.scipy.org/pipermail/numpy-discussion/attachments/20060602/a78477c7/attachment-0001.py
More information about the Numpy-discussion
mailing list