Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

removing APL nesting level question

164 views
Skip to first unread message

Don Wiss

unread,
Sep 6, 2012, 12:29:52 PM9/6/12
to
My APL learning years were before nested arrays came along. Hence I am weak
in certain areas. I am using APL+Win.

I have 1600 recipes in 43 chapters. I have a vector of 43 and each element
is a vector of the recipe names in that chapter. I'd like to remove a level
of nesting and end up with a vector of the 1600 names.

It must be something real simple...

Don. www.paleofood.com (e-mail link at home page bottom).

Rav

unread,
Sep 6, 2012, 1:13:02 PM9/6/12
to
Assuming your 43-item vector looks like this (here, just 4 chapters):

⍴a←(,⊂'Only one recipe in this chapter') ('Ch 2 Recipe 1' 'Ch 2
Recipe 2') (0⍴⊂'') ('Ch4 R1' 'Ch4 R2' 'Ch4 R3')
4
⍴¨a ⍝ Number of recipes in each chapter.
1 2 0 3

Then this will do what you want, I think:

⍴⊃,/a
6

/Rav

Graham

unread,
Sep 6, 2012, 3:22:49 PM9/6/12
to

"Don Wiss" <donwiss@no_spam.com> wrote in message news:7gjh4892043kfd416...@4ax.com...
> My APL learning years were before nested arrays came along. Hence I am weak
> in certain areas. I am using APL+Win.
>
> I have 1600 recipes in 43 chapters. I have a vector of 43 and each element
> is a vector of the recipe names in that chapter. I'd like to remove a level
> of nesting and end up with a vector of the 1600 names.
>
> It must be something real simple...

Enlist

Return a simple vector comprising the simple items of arg arranged in depth first row-major order. R is any array.



r← ∊{your 43 element vector} should do the trick



Graham.

Rav

unread,
Sep 6, 2012, 6:09:23 PM9/6/12
to
If what he wants to end up with is a 1600 element vector, with each
element containing one recipe, then enlist will not do it -- it would go
"too far." Enlist would remove ALL levels of nesting (he indicated
remove "a" level, which I interpreted as meaning one level), and he'd
end up with one simple character vector containing all the recipes all
smooshed together. Don, clarification?

Don Wiss

unread,
Sep 7, 2012, 12:00:10 AM9/7/12
to
On Thu, 06 Sep 2012 13:13:02 -0400, Rav <Pa...@cais.com> wrote:

>On 9/6/2012 12:29 PM, Don Wiss wrote:
>> I have 1600 recipes in 43 chapters. I have a vector of 43 and each element
>> is a vector of the recipe names in that chapter. I'd like to remove a level
>> of nesting and end up with a vector of the 1600 names.

>Then this will do what you want, I think:
>
> ??,/a

As in: {take},/a

Yes. That works just fine. Thanks.

Don. www.donwiss.com (e-mail link at home page bottom).

Charles Brenner

unread,
Sep 7, 2012, 2:39:44 PM9/7/12
to
On Sep 6, 9:00 pm, Don Wiss <donwiss@no_spam.com> wrote:
> On Thu, 06 Sep 2012 13:13:02 -0400, Rav <Pa...@cais.com> wrote:
> >On 9/6/2012 12:29 PM, Don Wiss wrote:
> >> I have 1600 recipes in 43 chapters. I have a vector of 43 and each element
> >> is a vector of the recipe names in that chapter. I'd like to remove a level
> >> of nesting and end up with a vector of the 1600 names.
> >Then this will do what you want, I think:
>
> >       ??,/a
>
> As in: {take},/a
>
> Yes. That works just fine. Thanks.

You are right; {take} works. But the symbol Rav used which may have
gotten lost in your browser was a disclose (right horseshoe). Just as
a matter of esthetics I like disclose better. The shape of ,/a is the
shape of a scalar. {take} of it means take the first element, but
there really is no "first" element of a scalar just as there is no
first element of a 3x4 matrix. Given that {take}3 4{rho}'asdfasdfasdf'
isn't allowed, the fact that {take}7 or {take},/a is allowed feels to
me not to be purist APL.

Charles

Rav

unread,
Sep 7, 2012, 3:55:16 PM9/7/12
to
Hi, Charles. While I happen to agree with you that disclose is
preferable (since the intent is to remove a level of nesting, and not
take the "first" element), and that's why I used it, at least in APL+Win
and NARS2000 {take}3 4{rho}'asdfasdfasdf' does work (returns 'a'). I
don't know about Dyalog or others.

Aaron W. Hsu

unread,
Sep 7, 2012, 8:34:47 PM9/7/12
to
Rav <Pa...@cais.com> writes:

>Hi, Charles. While I happen to agree with you that disclose is
>preferable (since the intent is to remove a level of nesting, and not
>take the "first" element), and that's why I used it, at least in APL+Win
>and NARS2000 {take}3 4{rho}'asdfasdfasdf' does work (returns 'a'). I
>don't know about Dyalog or others.

In Dyalog there is the migration level. If you are using migration
levels greater than 2, then I am not sure what using {take} would do,
but I think it would have the effect of being a first or disclose
operation and would work on 3 4⍴⍳12 for example. However, with migration
levels below 2, which is the default, ↑3 4⍴⍳12 gives you the same
thing back, while ⊃3 4⍴⍳12 gives you 1. I think this is because
the {take} function in migration level 0 flattens out a list that is
nested. That is, (⍴↑3 4⍴⊂⍳12)≡3 4 12.


--
Aaron W. Hsu | arc...@sacrideo.us | http://www.sacrideo.us
Programming is just another word for the lost art of thinking.

Charles Brenner

unread,
Sep 9, 2012, 1:26:24 PM9/9/12
to
Right you are, also with the DOS versions of Manugistics APL (versions
5 & 6 -- called APL+DOS I think but I'm never sure) that I've been
using for years, always incorrectly assuming that this pearl of an
expression was unavailable to me. The times I could have had!

Charles

0 new messages