Thanks!

On 06/01/2013 08:13 PM, Devon McCormick wrote:
> 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

----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to