Mathematica 9 is now available
Student Support Forum
-----
Student Support Forum: 'K-NN on equispaced grid' topicStudent Support Forum > General > "K-NN on equispaced grid"

Help | Reply To Topic
Author Comment/Response
e
12/08/06 09:18am

I'm looking for fun such that fun[x] returns the K-NN of x an equispaced grid where

x=(x_1,...,x_D) where x_d takes values in (...,-1,0,1,...) for any d=1,...,D

for example if D=2 and x=(0,0) the

1-NN is x itself
5-NN are x, (-1,0), (0,-1),(1,0),(0,1)
9-NN are x, (-1,0), (0,-1),(1,0),(0,1),(-1,-1),(-1,1),(1,-1),(1,1)

for example, if i do
tmp=Flatten[Outer[List,{0,-1,1},{0,-1,1}],1]

it returns the 9-NN but not in the right order so that Take[tmp,6] returns
{{0,0},{0,-1},{0,1},{-1,0},{-1,-1},{-1,1}}
which is not the 6NN because {1,0} is excluded.

I could possibly sort tmp in appropriate way but i'm hoping there's a neater way.










URL: ,
Help | Reply To Topic