An algorithm puzzle [message #60788] |
Fri, 13 June 2008 20:43  |
Y.T.
Messages: 25 Registered: December 2004
|
Junior Member |
|
|
Imagine there's a byte-array named "P" that contains only zeros and
ones:
IDL> help,p
P BYTE = Array[5000, 4250]
IDL> print,n_elements(where(p eq 0 or p eq 1))
21250000
IDL> print,5000L*4250
21250000
I am trying to construct a new (lon)array "D" with the same dimensions
as "P" with the following properties:
If P[x,y] eq 0 then D[x,y] = 0 (this part is easy)
If P[x,y] eq 1 then D[x,y] = the smallest distance between {x,y} and a
point in P that is equal to 0
In essence I'd like to know how far each non-zero "pixel" in p is from
a place that is zero (so that I can do statistics on the frequency of
certain distances and such).
I'm currently brute-forcing it with two for-loops where I calculate
the distance between every single element and every single "other"
element and then finding the minimum. Needless to say this takes about
a metric forever and I figured you folks usually have really clever
ideas so I'm throwing this out here to see whether there isn't some
obscure usage of histogram that does exactly what I want...
cordially
Y.T.
|
|
|
Re: An algorithm puzzle [message #60900 is a reply to message #60788] |
Mon, 16 June 2008 10:47  |
Jelle
Messages: 19 Registered: May 2008
|
Junior Member |
|
|
Hahahaha,
It is not about victories or prices, it is about the everlasting
honour in the great wall of fame, isn't it?
I do not seriously need the T-Shirt. You helped me so many times in
the past with some snippets -and larger projects- that I'll consider
that as my price. :)
Cheers,
J
|
|
|
Re: An algorithm puzzle [message #60903 is a reply to message #60788] |
Mon, 16 June 2008 06:20  |
David Fanning
Messages: 11724 Registered: August 2001
|
Senior Member |
|
|
Jelle writes:
> ehr..
> Even though IDL has it built in, it was new to YT, wasn't it? You
> asked for a solution that ran in less than 10sec, you didn't specify
> that the function had to be coded by that person :|
>
> I find my solution perfectly acceptable! :D
Alright, I learned long ago as a tennis player that if
people won't lose to you, there *are* no victories, so
I'll send the shirt along. (Assuming I can stuff it under
my shirt as I'm walking out of the place.)
Let me know where to send it. You can find my e-mail
address in the usual secret places I use to put the
spammers off my tail.
Cheers,
David
--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Sepore ma de ni thui. ("Perhaps thou speakest truth.")
|
|
|
Re: An algorithm puzzle [message #60912 is a reply to message #60788] |
Mon, 16 June 2008 03:16  |
Jelle
Messages: 19 Registered: May 2008
|
Junior Member |
|
|
On Jun 16, 5:29 am, David Fanning <n...@dfanning.com> wrote:
> Y.T. writes:
>> Wow - I'm looking for a clever solution and IDL has a built-in.
>
> Who would have thunk it!?
>
> But, I don't know. It's sort of bogus to steal a T-shirt
> from ITTVIS and then turn around and give it back to them.
> Any suggestions? :-(
>
> Cheers,
>
> David
ehr..
Even though IDL has it built in, it was new to YT, wasn't it? You
asked for a solution that ran in less than 10sec, you didn't specify
that the function had to be coded by that person :|
I find my solution perfectly acceptable! :D
|
|
|
Re: An algorithm puzzle [message #60915 is a reply to message #60788] |
Sun, 15 June 2008 21:29  |
David Fanning
Messages: 11724 Registered: August 2001
|
Senior Member |
|
|
Y.T. writes:
> Wow - I'm looking for a clever solution and IDL has a built-in.
Who would have thunk it!?
But, I don't know. It's sort of bogus to steal a T-shirt
from ITTVIS and then turn around and give it back to them.
Any suggestions? :-(
Cheers,
David
--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Sepore ma de ni thui. ("Perhaps thou speakest truth.")
|
|
|