Applying this to a higher-dimensional array illustrates how it works on
rank 1 sub-arrays:

   ]mat=. 1 2 3 _1 99 4 5, _1 2 99 3 4 5 1,: 5 4 3 99 2 _1 1
 1 2  3 _1 99  4 5
_1 2 99  3  4  5 1
 5 4  3 99  2 _1 1

   whereHiLo mat
4 3
2 0
3 5


On Sat, Jun 1, 2013 at 2:09 PM, Devon McCormick <[email protected]> wrote:

> It looks like the nature of this problem is scalar, so you'd need one that
> naturally applies to a different rank.  For instance, we may want to find
> the locations of the (first instance of) smallest and largest number in a
> vector of numbers.  This naturally applies to a vector (one-dimensional
> array) and returns a vector.
>
> So, we find the largest number by ">./" and look it up with "i." -
> combining these gives us the tacit expression "]i.>./" .  Finding the
> smallest has the same form but uses "<." instead of ">.".  Combining the
> two results, specifying we want to work on 1-D sub-arrays, naming and
> testing this might give us something like this:
>
>
>    whereHiLo=: ((]i.>./),(]i.<./))"1    NB. Excess parens are
>    whereHiLo                                 NB. dropped from the
> definition
> ((] i. >./) , ] i. <./)"1
>
>    whereHiLo i.10
> 9 0
>    whereHiLo |.i.10
> 0 9
>
>    whereHiLo 5 6 7 _1 3 4 5 99 1 2 3
> 7 3
>
>
>
>
> On Sat, Jun 1, 2013 at 12:46 PM, Olivier N. <
> [email protected]> wrote:
>
>> Thanks for this tip!
>>
>> I'm fairly new to J and didn't know how to deal with this
>> and I discovered the &> just a few days ago, thanks to Arie.
>>
>> Could you explain to me how I could've written my verb
>> so it could work with non scalar inputs?
>>
>> Regards,
>>
>> Olivier
>>
>> On 06/01/2013 05:24 PM, Devon McCormick wrote:
>> > I notice you apply your solution, using &> to each item of your
>> > (simple=unenclosed) input and return a single scalar for each scalar
>> > input.  It occurs to me that your definition could be more descriptive
>> if
>> > you made its scalar orientation explicit.  That is, you could change the
>> > first line of your definition to read
>> >
>> >    tricnt =: 3 : 0"0
>> >
>> > so that you could apply it more simply, e.g.
>> >
>> >    tricnt 54+i.6
>> >
>> > The above definition form is also helpful to those of us reading your
>> code
>> > by alerting us that you expect a scalar input.
>> >
>> > Regards,
>> >
>> > Devon
>>
>> ----------------------------------------------------------------------
>> For information about J forums see http://www.jsoftware.com/forums.htm
>>
>
>
>
> --
> Devon McCormick, CFA
> ^me^ at acm.
> org is my
> preferred e-mail
>



-- 
Devon McCormick, CFA
^me^ at acm.
org is my
preferred e-mail
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to