I have an array of about 300,000 numbers (0.000000) and want to review each of those numbers to choose those which are within .01 of one another. So, in essence this is 300,000^300,000 values I guess, which takes a while to calculate. I do this simply by loading an array, and then comparing each value in that array with all other values by way of a loop within a loop.
The problem is this takes about 10 hours or so to complete, at the least. Can any Monk recommend a coding solution that could speed this up? I tried using PDL but that resulted in no noticeable speed increase. Relevant portions of the code are below...
for ($n=0;$n<=$#lat;$n++) {
for ($v=0;$v<=$#lat;$v++) {
if ($lat[$n] > $lat[$v]-.01 &&
$lat[$n] < $lat[$v]+.01 &&
$long[$n] > $long[$v]-.01 &&
$long[$n] < $long[$v]+.01) {
if ($numbdate[$n] == ($numbdate[$v]+1) &&
$timestamp[$n] > 1400 &&
$timestamp[$v] < 1400) {
$e++;
};
if ($numbdate[$n] == ($numbdate[$v]) &&
$timestamp[$n] < ($timestamp[$v]-400)) {
$d++;
};
}
}
}
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.