« first day (2060 days earlier)      last day (597 days later) » 

12:33 PM
@rak1507 Fixed in 19.0
 
Here is a fun (silly) way to divide by an integer {(⍎1↓⊃,⌿⍵⍴⊂'++')⍣¯1⊢⍺}
 
 
2 hours later…
3:00 PM
Welcome to APL Quest 2016-3! Today's quest is Statistics - Mode:
> Write a function that takes a numeric vector or scalar as its right argument and returns the mode of the array.
 
 {c←{⍺ (≢⍵)}⌸ ,⍵ ⋄ c[;1]/⍨c[;2]⍷⍨⌈/c[;2]}
 
At least, this time, we don't have to special-case the empty argument.
@Richard Why ?
 
To find where the highest value's are
 
Sure, but that's the same as =, no?
 
ah, yes ...
 
3:03 PM
X f g X can be written f∘g⍨X
 
Good morning!
 
Hello!
You're just in time for the quest.
 
Yep. Finally able to make one.
:)
 
Hey Steve
 
Hey Richard
 
3:05 PM
@Richard Can you see how you can use my f g hint?
 
looking at it. f = '=' and g = ⌈/
 
Yes.
 
c[;2] = X
 
Just watch out for binding strengths.
 
Ans is ⌸ necessary? Or is there a better way to count them?
 
3:08 PM
I think that's best. Otherwise you need an outer product.
 
yes
 
There are other ways to use though, and other ways to use its result.
 
Trying to replace with your suggestion but is not working yet. I'm not so fast, sorry
 
What did you try?
 
c[;1]/⍨=∘⌈/⍨c[;2]
 
3:12 PM
Ah, binding strength indeed: ⎕←=∘⌈/⍨
 
parenthesis I also tried
 
@Adám
     ⍨
   ┌─┘
   /
 ┌─┘
 ∘
┌┴┐
= ⌈
 
So is binding = to and that becomes the operand for /.
 
{c←{⍺(≢⍵)}⌸,⍵ ⋄ c[;1]/⍨=∘(⌈/)⍨c[;2]}
 
Yes! You want ⌈/ to be the operand of .
Now, what if you named the values and the tallies separately? (v t)←{⍺(≢⍵)}⌸
Btw, since all values are simple scalars, you can use {⍺,≢⍵}
 
3:15 PM
then c[;1] becomes v and c[;2] becomes t
 
Right. What could you write where I put "…"?
 
I'm thinking something like this: {(v t)←{⍺,≢⍵}⌸⍵ ⋄ (t=⌈/t)/v} But I'm getting a Rank error on the assignment.
 
Right, because you're trying to put a matrix into a vector (list of names).
So you need to convert the 2-column matrix to a 2-element vector.
 
Ah, right. Gimme a sec
 
 
3:17 PM
That's half of one way to do it.
 
no
 
{(v t)←↓⍉{⍺,≢⍵}⌸⍵ ⋄ (t=⌈/t)/v}
 
Very nice.
 
↓⍉
 
Another way to do it is ,⌿ — do you get why?
 
3:19 PM
viz?
Oh .... is assignment actually a function?
 
Namely‽
I mean (v t)←,⌿{⍺,≢⍵}⌸⍵
 
Oh, right. That makes sense.
Which is faster?
 
I'd guess ,⌿ because it can directly extract the data. can be expensive as it has to shuffle all elements.
 
hm.....that makes me wonder if that can't just be put into the key's left function.
 
Not really. It returns one major cell per unique element.
 
3:22 PM
Oh ok
 
However, we can (ab)use that in a different way.
 
LOL I love abusing functions for fun and profit. :P
 
@SteveAllen this is very readable, nice
 
Instead of finding the counts, lets just show the indices: ⎕←{⊢⌸⍵}¨(3 1 4 1 5)(2 7 1 8 1 8 1 8)
 
@Adám
┌───┬─────┐
│1 0│1 0 0│
│2 4│2 0 0│
│3 0│3 5 7│
│5 0│4 6 8│
└───┴─────┘
 
3:24 PM
Do you understand this result? In particular, what are the 0s?
 
{∧/u←≠⍵: ⍵ ⋄ ∇⍵/⍨~u} doesn't seem to work on the site, but I don't get why
{∧/u←≠⍵: ⍵ ⋄ ∇⍵/⍨~u} should have returned 7 with (7) as right argument
 
Oh, clever.
@rak1507 The problem is that it should return a vector of the modes. Returns a scalar for a scalar.
 
@Adám no not yey, cause I am still stukc at the ⊢⌸⍵
 
Oh, that's just {⍵}⌸
 
@Adám ah :/
 
3:27 PM
@rak1507 If you use it'll even work for any rank.
 
does it require sorted order too?
 
So, before, we were counting the occurrences: ⎕←{{≢⍵}⌸⍵}¨(3 1 4 1 5)(2 7 1 8 1 8 1 8)
 
@Adám
┌───────┬───────┐
│1 2 1 1│1 1 3 3│
└───────┴───────┘
 
@rak1507 Not sure. It doesn't say.
Here are the indices themselves: ⎕←{{⊂⍵}⌸⍵}¨(3 1 4 1 5)(2 7 1 8 1 8 1 8)
 
sorting seems to work, but also just order of occurrence too
 
3:29 PM
@Adám
┌───────────┬─────────────────┐
│┌─┬───┬─┬─┐│┌─┬─┬─────┬─────┐│
││1│2 4│3│5│││1│2│3 5 7│4 6 8││
│└─┴───┴─┴─┘│└─┴─┴─────┴─────┘│
└───────────┴─────────────────┘
 
{∧/≠⍵:,⍵ ⋄ ∇⍵/⍨~⌽≠⌽⍵}
 
The is necessary because returns a major cell per element, so we'd get a matrix. However, matrices cannot be ragged; it has to pad them, and will do so with 0s.
 
@Adám Are the two vectors as input intended to indicate two different inputs, or something else?
 
@Adám one column for each occurence
 
@SteveAllen Yes, note the ¨ — they are just two test cases.
@Richard Exactly! So the rightmost column will have indices for the modes (together with a bunch of 0s).
All we need to do is isolate that rightmost column and remove the 0s.
 
3:32 PM
Which is a compress
 
You don't even need that. Set different will do.
 
{⍵/⍨~(⊢>∧/)⌽≠⌽⍵}⍣≡
 
⍵[0~⍨⊢⌿]
 
⊢⌿ gives the bottom row, so you need ⊢/
Yes. ⎕←{0~⍨⊢/⊢⌸⍵}¨(3 1 4 1 5)(2 7 1 8 1 8 1 8)
 
@Adám
┌─┬───┐
│4│7 8│
└─┴───┘
 
3:35 PM
⎕←{⍵[0~⍨⊢/⊢⌸⍵]}¨(3 1 4 1 5)(2 7 1 8 1 8 1 8)
 
@Adám
┌─┬───┐
│1│1 8│
└─┴───┘
 
:)
 
@rak1507 Will be even nicer with
 
and under
 
I had (⊣/(/⍨)∘(⊢=⌈/)⊢/),∘≢⌸
 
3:37 PM
By why not ~ & >?
 
@Adám Right. I'm slow. :)
 
@Adám only doesn't like a scalar or ⍬. but can be fixed
 
oh, ~(⊢>∧/) can be (~∨∧/)
 
{⍵⌷⍨⊂0~⍨⊢/⊢⌸⍵} appears to work, too.
 
@Richard Right, easy with only one ?
@SteveAllen Yes, and that's better because it works for high-rank arrays.
@rabbitgrowth That's the tacit edition, yes.
@rak1507 Or (⊢≤∧/), no?
 
3:40 PM
@Adám Suffers from the same problem @Richard pointed out though, re scalars & ⍬
 
@Adám yeah
 
(Oh, wait, there are two .)
@SteveAllen You can fix that with 1/⍵ — a trick to convert a scalar into a 1-element vector, all other arrays staying as they are.
@rak1507 ∧/⍛≥⍤≠⍢⊖⍛⌿⍣≡?
 
that's more like it!
 
Look ma, no trains!
OK, one more trick before we stop. {(v t)←↓⍉{⍺,≢⍵}⌸⍵ ⋄ (t=⌈/t)/v} can be done without assignment.
Since we only have two arrays, and ↓⍉ or ,⌿ gives them as a vector, we can use reduce to insert a function between them.
 
@Adám {⍵/⍨{≢⍵}⌸⍵}, right?
 
3:47 PM
Uh, that's not a full solution.
 
oops forgot the max
 
And you'll get a mask for the unique elements, not the original array.
Rather unfortunate to have to do ∪⍵ when already did that internally.
So we can write {⊃{(⍵=⌈/⍵)/⍺}/↓⍉{⍺,≢⍵}⌸⍵}
OK, fine, one more thing: {⍺,≢⍵} is ,∘≢
 
???
 
Regarding what?
 
,∘⌸
 
3:50 PM
That's not what I wrote.
 
ah, tired eyes
 
Shall we call it a day, then?
 
Some attention to the weekgolf page? one vote short
 
link?
 
3:52 PM
@Adám Has it been an hour already? Dang ... time flies. :)
@Adám Thanks
 
See you next week for 2016-4: Just Meshing Around. Don't forget that we'll start 2 hours earlier, beginning in 4 weeks, 14 October.
 
thanks, next week!
 
 
3 hours later…
6:32 PM
Was a little confused by the cyclic reshape. But I think I understand now.
 

« first day (2060 days earlier)      last day (597 days later) »