bug-apl
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Bug-apl] Help with APL expression


From: Christian Robert
Subject: Re: [Bug-apl] Help with APL expression
Date: Fri, 7 Jul 2017 01:43:20 -0400
User-agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:52.0) Gecko/20100101 Thunderbird/52.2.1

That kind of expression really get me on my knees.

thanks for sharing,

Xtian.


On 2017-07-06 17:54, Ala'a Mohammad wrote:
Oops, the second solution should be

  (1+c[x]) ⊂ s[x←⍋c]

Ala'a

On Fri, Jul 7, 2017 at 1:38 AM, Ala'a Mohammad <address@hidden> wrote:
Hi,
Another two ways, Not as compact or optimized, but generate the same output
1)
G groups, C categories, and S strings

G←(⍴∪C)⍴⊂⍬ ◊ C {G[⍺]←⊂(⊃G[⍺]),⊂⍵}¨S ◊ G

I forgot how to suppress the middle output
or in a function

∇ groups ← categories group items
   groups ← (⍴∪categories)⍴⊂⍬
   categories {groups[⍺]←⊂(⊃groups[⍺]),⊂⍵}¨ items

2)
(1+C[x]) ⊂ S[(⍳⍴C)[x←⍋C]]

Best wishes,

Ala'a

On Wed, Jul 5, 2017 at 2:48 PM, Louis de Forcrand <address@hidden> wrote:
Is it important that they be grouped in the order specified by the key?
If not, this should do (with C the categories and S the strings):

(⊂[1]C∘.=∪C)/¨⊂S

If they must be ordered, then this can do it:

(⊂[1]C∘.=U[⍋U←∪C])/¨⊂S

In addition, the categories don’t have to be numbers.

Note that Dyalog’s (dyadic) key function is equivalent to this, with L being
the operator’s left operand:

L¨(⊂[1]C∘.=∪C)/¨⊂S

Cheers,
Louis

On 05 Jul 2017, at 11:43, Elias Mårtenson <address@hidden> wrote:

I have a list of strings, and a corresponding set of categorisations:

       strings ← 'foo' 'bar' 'abc' 'def' 'ghi' 'jkl'
       categories ← 1 1 0 2 1 0

I now need to group these strings according to category. In other words,
when applying operation X, I need the following output:

       categories X strings
┏→━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
┃┏→━━━━━━━━━━┓ ┏→━━━━━━━━━━━━━━━━┓ ┏→━━━━┓┃
┃┃"abc" "jkl"┃ ┃"foo" "bar" "hgi"┃ ┃"def"┃┃
┃┗∊━━━━━━━━━━┛ ┗∊━━━━━━━━━━━━━━━━┛ ┗∊━━━━┛┃
┗∊∊━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛

What is the best way to solve this?




reply via email to

[Prev in Thread] Current Thread [Next in Thread]