[Numpy-discussion] Z-ordering (Morton ordering) for numpy
Travis Oliphant
travis@continuum...
Sat Nov 24 14:10:48 CST 2012
This is pretty cool. Something like this would be interesting to play with. There are some algorithms that are faster with z-order arrays. The code is simple enough and small enough that I could see putting it in NumPy. What do others think?
-Travis
On Nov 24, 2012, at 1:03 PM, Gamblin, Todd wrote:
> Hi all,
>
> In the course of developing a network mapping tool I'm working on, I also developed some python code to do arbitrary-dimensional z-order (morton order) for ndarrays. The code is here:
>
> https://github.com/tgamblin/rubik/blob/master/rubik/zorder.py
>
> There is a function to put the elements of an array in Z order, and another one to enumerate an array's elements in Z order. There is also a ZEncoder class that can generate Z-codes for arbitrary dimensions and bit widths.
>
> I figure this is something that would be generally useful. Any interest in having this in numpy? If so, what should the interface look like and can you point me to a good spot in the code to add it?
>
> I was thinking it might make sense to have a Z-order iterator for ndarrays, kind of like ndarray.flat. i.e.:
>
> arr = np.empty([4,4], dtype=int)
> arr.flat = range(arr.size)
> for elt in arr.zorder:
> print elt,
> 0 4 1 5 8 12 9 13 2 6 3 7 10 14 11 15
>
> Or an equivalent to ndindex:
>
> arr = np.empty(4,4, dtype=int)
> arr.flat = range(arr.size)
> for ix in np.zindex(arr.shape):
> print ix,
> (0, 0) (1, 0) (0, 1) (1, 1) (2, 0) (3, 0) (2, 1) (3, 1) (0, 2) (1, 2) (0, 3) (1, 3) (2, 2) (3, 2) (2, 3) (3, 3)
>
> Thoughts?
>
> -Todd
> ______________________________________________________________________
> Todd Gamblin, tgamblin@llnl.gov, http://people.llnl.gov/gamblin2
> CASC @ Lawrence Livermore National Laboratory, Livermore, CA, USA
>
> _______________________________________________
> NumPy-Discussion mailing list
> NumPy-Discussion@scipy.org
> http://mail.scipy.org/mailman/listinfo/numpy-discussion
More information about the NumPy-Discussion
mailing list