Try
rng =: ] #~ 1=I.
it's about half as fast because I. is not very well-optimized.
Marshall
On Sun, Sep 24, 2017 at 02:29:31AM -0500, Skip Cave wrote:
> Here's a function I came up with to select numbers in a vector which are
> within some range.
>
> Find all the numbers between 10 & 100 in a set of random numbers from 0 to
> 200:
>
>
> rng =. 4 : '((({.x)</y)*.(({:x)>/y))#y'
>
>
> 10 100 rng ?50$200
>
> 89 91 32 85 84 27 31 20 28 66 96 93 22 85 39 97 82 35 90 67 34 35 67 95 50
>
>
> Between 120 & 180:
>
>
> 120 180 rng ?50$200
>
> 148 163 133 165 150 178 121 146 161 179
>
>
> Is there a more concise/efficient way to select numbers in a range?
>
> Skip Cave
> Cave Consulting LLC
> ----------------------------------------------------------------------
> For information about J forums see http://www.jsoftware.com/forums.htm
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm