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.
In reply to Re: first stumbling steps in PDL
by Anonymous Monk
in thread first stumbling steps in PDL
by Discipulus
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |