[Tutor] locations

linda.s samrobertsmith at gmail.com
Fri Apr 21 13:29:19 CEST 2006


I have a question. in the LIST M=
[[1,1,1,1],
[0,1,1,1],
[1,1,0,1],
[1,1,1,1]]
If treat them as the locations of 16 points, I want to generate another list
N to hold the corresponding value for each point to its nearest 0.
For example:
the nearest 0 point to M[0][0] is M[1][0], so N[0][0]=1;
M[0][1]'s nearest 0 is also at M[1][0], so N[0][1]=2;
but N[0][3]=3 because 0 at M[2][2] is much nearer;
N[1][0]=0 because the distance to itself is 0;
N should be
[[1,2,2,3],
[0,1,1,2],
[1,1,0,1],
[2,2,1,2]]
I am really very new to Python and have no idea how to write the code.
Thanks!
Linda
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20060421/38a5096c/attachment.htm 


More information about the Tutor mailing list