in reply to first stumbling steps in PDL
TIMTOWTDI, but PDL is not about explicit loops. Not how it works. Consider this vector:
pdl> p $v = pdl split '', '30373' [3 0 3 7 3]
Now then e.g. the cumulative sum or running total:
pdl> p cumusumover $v [3 3 6 13 16]
Not very useful, but I have a vague feeling that "cumulative maximum" would be handy if someone is looking at a forest. You could type
pdl> ?? cumulative
to investigate what's available. OK, then, consider "strictly lower triangular matrix" or whatever it's called in mathematics if non-zero members are all 1's:
pdl> p $SLTM [ [0 0 0 0 0] [1 0 0 0 0] [1 1 0 0 0] [1 1 1 0 0] [1 1 1 1 0] ]
Hm-m, looks interesting. Not sure about forestry, but what if it's multiplied by our vector?
pdl> p $SLTM * $v [ [0 0 0 0 0] [3 0 0 0 0] [3 0 0 0 0] [3 0 3 0 0] [3 0 3 7 0] ]
That's even more interesting! What could we use this result for? What about computing maximum over rows?
pdl> p maxover $SLTM * $v [0 3 3 3 7]
Now that's what I call interesting! Isn't it cumulative maximum of all elements before current for original vector? Let's check it without further ado:
pdl> p $v > maxover $SLTM * $v [1 0 0 1 0]
But wait, that's exactly the answer we were looking for -- what trees are seen if forest patch is looked at from the left!
And all the rest was just further expansion of investigation performed above.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: first stumbling steps in PDL
by etj (Priest) on Feb 02, 2024 at 19:12 UTC | |
by jo37 (Curate) on Feb 02, 2024 at 20:54 UTC | |
by etj (Priest) on Feb 03, 2024 at 03:54 UTC | |
by jo37 (Curate) on Feb 08, 2024 at 14:17 UTC | |
by eyepopslikeamosquito (Archbishop) on Feb 08, 2024 at 21:37 UTC | |
| |
by etj (Priest) on Feb 20, 2024 at 11:31 UTC | |
by etj (Priest) on Feb 11, 2024 at 00:16 UTC | |
by jo37 (Curate) on Feb 05, 2024 at 20:18 UTC | |
by etj (Priest) on Feb 06, 2024 at 17:58 UTC | |
| |
by jo37 (Curate) on Feb 04, 2024 at 09:56 UTC | |
by etj (Priest) on Feb 04, 2024 at 23:07 UTC | |
by jo37 (Curate) on Feb 06, 2024 at 08:30 UTC | |
by etj (Priest) on Feb 06, 2024 at 16:45 UTC |