g | x | w | all
Bytes Lang Time Link
073C240713T212534Zdanmcard
015Julia 1.0240713T195310ZMarcMush
038min240713T010129Zchunes
004Uiua SBCS231014T023404Zchunes
019Julia 1.0230914T173439ZAshlin H
005Pip p230914T183802ZDLosc
002Nekomata230912T081255Zalephalp
042Common Lisp230727T121209Zcoredump
029PowerShell Core230727T072609ZJulian
044Java230727T070859ZTop Golf
077Desmos230726T182019Znotaprot
027Arturo230118T022408Zchunes
001Thunno 2230726T110759ZThe Thon
4745AWK210422T010853ZJonah
nan230128T093830ZThe Thon
103Go230128T063157Zbigyihsu
013TIBasic230128T043000ZYouserna
nan230127T210747Znoodle p
002Pyt230127T195258ZKip the
032Matlab210513T183648Zelementi
023Zsh210424T144809Zpxeger
058Java210423T212417ZUnmitiga
006Arn210423T202722ZZippyMag
045Excel210423T195252ZEngineer
036Pari/GP210423T003740ZJoe Slat
nanExcel 17210422T225427ZAxuary
008Brachylog210421T235436ZUnrelate
022Perl 5 pa210422T163814ZXcali
080TSQL210422T155927ZBrian J
075C clang210422T114959ZNoodle9
002Neim210422T141426ZLiefdeWe
032C# Visual C# Interactive Compiler210422T140922ZLiefdeWe
056PHP210422T123700ZKaddath
004Japt210422T092604ZAZTECCO
006J210422T075454ZGalen Iv
042Racket210422T074324ZGalen Iv
035JavaScript ES2021210422T022145Ztsh
010Raku210422T025700ZSean
027Ruby210422T005117ZSony San
026R210422T005215ZGiuseppe
028Factor210422T002844Zchunes
012Wolfram Language Mathematica210422T003952Zatt
00105AB1E210422T003400ZMakonede
006APLDyalog Unicode210422T000202Zhyper-ne
022Scala210422T000200Zuser
003MATL210422T000007ZLuis Men
002Vyxal210421T234205Zlyxal
00205AB1E210421T234910Zlyxal
023Python 2210421T234856Zxnor
003Pyth210421T234649Zhakr14
026Python 3210421T234625Zcaird co
006Charcoal210421T234551ZNeil
036JavaScript ES6210421T234522ZArnauld
027Haskell210421T234403ZDelfad0r
002Jelly210421T233929Zcaird co

C, 73 bytes

void f(int*p,int*o,int n){for(int i=0;i<n*n;++i)o[i/n]+=p[i/n]==p[i%n];}

Slightly more readable:

void f_pretty(int* p, int* o, int n) {
  for (int i = 0; i < n * n; ++i)
    o[i / n] += p[i / n] == p[i % n];
}

One trick I'm pulling is replacing nested for loops for (int i=0; i<n; ++i) for (int j=0; j<n; ++j) with for (int k=0; k<n*n; ++k). In the second form, I can reconstruct the original i as k / n and the original j as k % n.

Julia 1.0, 15 bytes

!a=(a.==a')a./a

Try it online!

min, 41 38 bytes

(:q q((==)cons q swap filter size)map)

enter image description here

(...)      ; a function
:q         ; assign input to q
q          ; push input to stack
()map      ; map over input by...
(==)cons   ; prepend current elt to (==), forming (1 ==) for instance
q swap     ; push input and put it underneath
filter     ; filter input by function we created
size       ; get length of list

Uiua SBCS, 5 4 bytes

⊏⟜°⊚

Try it!

Works with natural numbers.

   °⊚   # inverse where (occurrences)
⊏⟜      # select from occurrences using input as indices

Julia 1.0, 19 bytes

~a=@.sum(==(a),[a])

Try it online!

Saved 2 bytes by substituting sum for count.

-3 bytes thanks to MarcMush: replace Ref(a) with [a]

Pip -p, 5 bytes

_NgMg

Attempt This Online!

Explanation

    g  ; List of command-line args
   M   ; Map to each:
_N     ;  Number of occurrences of that argument in...
  g    ;  ... the list of command-line args

Nekomata, 2 bytes

ᵐĈ

Attempt This Online!

ᵐĈ
ᵐ   Map
 Ĉ  Count

Common Lisp, 42

(lambda(x)(mapcar(lambda(u)(count u x))x))

PowerShell Core, 29 bytes

($a=$args)|%{($a-eq$_).count}

Try it online!

Java, 44 Bytes

n.stream().map(e->frequency(n1,e)).toList();

with n1 beeing a copy of n and static import of java.util.Collections.*

Desmos, 77 bytes

f(a)=\sum_{n=[1...a.length]}^{[1...a.length]}(total(\left\{a=a[n],0\right\}))

Try it online! Takes in a list as input, and outputs a new list as per the specifications. The linked graph uses an action to replace the list with the function's output.

Arturo,  34  27 bytes

$->a[map a=>[get tally a&]]

Try it!

Thunno 2, 1 byte

c

Try it online!

Just the count command, vectorised over the array implicitly.

AWK, 47 45 bytes

{++f[l[++n]=$1]}END{for(x in l)print f[l[x]]}

Try it online!

-2 thanks to cnamejj

Thunno, \$ 2\log_{256}(96)\approx\$ 1.65 bytes

Dc

Attempt This Online!

Or, \$1 \log_{256}(96) \approx\$ 0.82 bytes with the D flag!: Attempt This Online!

D duplicates the (implicit) input, and c gets the count of each one (vectorises automatically).

Edit: Just realised that there's another Thunno answer here. I'll keep this undeleted, though, since it is different from the other answer.

Go, 103 bytes

func f(l[]int)[]int{m:=make(map[int]int)
for _,e:=range l{m[e]++}
for i,e:=range l{l[i]=m[e]}
return l}

Attempt This Online!

TI-Basic, 13 bytes

seq(sum(I=Ans),I,1,dim(Ans

Takes input in Ans.

Thunno, \$ 2 \log_{256}(96) \approx \$ 1.65 bytes

ec

Attempt This Online!

ec : implicit input array
e  : map the input to the following:
 c :   count the occurrences of the number in the input
   : implicit output

Thought I'd try an easy and short problem for my first Thunno answer.

Pyt, 2 bytes

Đɔ

Try it online!

Đ      implicit input; duplicate
 ɔ     for each item in input, count occurrences in input; implicit print

Matlab, 32 bytes

@(x)table(histcounts(x)).Var1(x)

...assuming inputting only integer numbers from 1 to 50. Rules says I can choose a subset.
To work for integers from 1 to 65536 (216) you need few extra bytes and code like that:

@(x)table(histcounts(x,'BinMethod','int')).Var1(x)

Both solutions are anonymous functions.
The fragment of code table(...).Var1(x) is a trick allowing for indexing the function output without saving it to a variable. Normally one would do something like that:

y = histcounts(x);
return y(x)

but anonymous functions doesn't allow for that and full function would be longer.

The solution unfortunatelly doesn't work for Octave, because it doesn't have histcounts implemented. :(

Zsh, 23 bytes

xargs -I. grep -c . f<f

Try it online!

Java, 58 bytes

l->l.stream().map(x->java.util.Collections.frequency(l,x))

Try it online!

Java, 56 bytes

l->l.stream().map(x->l.stream().filter(y->y==x).count())

This only works for integers in the Integer Cache (-128 to 127, by default).

Try it online!

Arn, 6 bytes

█Â(ÂÍL

Found some pretty major precedence bugs... so that's why I'm a day late

Explained

Unpacked: @a{/:=a

  _       STDIN; implied
@         Bind following to each value
  a{         Block with key of 'a'
     /:      Bind next arg with the arg after, use truthiness to filter and then count
          _    Current value, implicit
        =      Equals
          a    Current value of map bind (defined by block)
        _    It's binded to STDIN
  }

Came up with some alternatives when I got bored from fixing the bug, here are some

Arn, 8 bytes

ñ=èÍù«Á&

Unpacked: @a{+{=a}\ (Replace each val with a mapped for equality + folded version of stdin)

Arn, 8 bytes

hLdŠÅk$'

Unpacked: @a{+\(@=a (Same as last one but written a different way)

Arn, 6 bytes

╔½†Œ#ç

Unpacked: @a{$=a&# (Very similar to the actual answer, but uses filter and a binded size suffix. Compression shaved two bytes off of this, instead of the one byte my real answer lost from compression, which is why they're the same length)

Excel, 45 bytes

=COUNTIF(A:A,INDEX(A:A,SEQUENCE(COUNT(A:A))))

Input is in column A. The formula goes anywhere not in column A.

COUNT(A:A) counts the numeric entries.
SEQUENCE(~) creates an array from 1 to whatever that count was.
INDEX(A:A,~) pulls the inputs one at a time, thanks to the sequence input.
COUNTIF(A:A,~) counts the inputs that match the one it just pulled.

Screenshot

Pari/GP, 36 bytes

f(v)=apply(x->sum(i=1,#v,x==v[i]),v)

Try it online!

Excel 17, bytes

=COUNTIF(A1#,A1#)

Assuming A1 = { .... } then this works. It's a longer, less flexible formula if the data in entered in individual cells.

Brachylog, 8 bytes

∋;?{∈ᵈ}ᶜ

Try it online!

Generates the output through the output variable.

∋;          Pair some element of the input with
  ?         the input.
   {  }ᶜ    In how many ways is
    ∈ᵈ      the element an element of the input?

Using comes out one byte longer:

Brachylog, 9 bytes

⟨ọ⟨∋h⟩∋⟩t

Try it online!

Also generates the output through the output variable.

      ∋      Choose an element of the input.
  ⟨ h⟩       It is the first element of
   ∋         an element of
⟨ọ     ⟩     the list of pairs [element of input, how many times it occurs in input]
        t    the last element of which is the output.

Perl 5 -pa, 22 bytes

s/\S+/grep$_==$&,@F/ge

Try it online!

T-SQL, 80 bytes

SELECT c FROM (SELECT a b,COUNT(*)c FROM @ GROUP BY a)x JOIN @ ON a=b ORDER BY i

Example Input

Requires something like this for input

DECLARE @ TABLE (a int, i int identity)
INSERT INTO @ VALUES (1), (2), (2), (4), (4), (4), (4)

Explanation

Group by the number and count them up. Then join back to the original list so that we can output in the correct order.

C (clang), 84 \$\cdots\$ 81 75 bytes

Saved 6 bytes thanks to AZTECCO!!!

b;i;j;f(*a,l){for(i=-1;++i<l;printf("%d ",b))for(b=j=l;j--;)b-=a[i]!=a[j];}

Try it online!

Inputs a pointer to an array and its length (because array pointers in C don't carry any length info) and prints the occurrence counts.

Neim, 2 bytes

Right language, right time.

Ψ𝕠

Try it online!

Explanation:

Ψ  # Apply next token to all in list
 𝕠 # Count element in list

C# (Visual C# Interactive Compiler), 32 bytes

Nothing special

a=>a.Select(x=>a.Count(y=>x==y))

Try it online!

PHP, 56 bytes

fn($a)=>array_map(fn($e)=>array_count_values($a)[$e],$a)

Try it online!

As usual, those "array_" PHP prefixes are ruining the golfing :P

Japt, 4 bytes

£è¥X

Try it

maps input by returning number of occurrence in input

J, 6 bytes

1#.=/~

Try it online!

K (oK), 9 bytes

{+/x=\:x}

Try it online!

Racket, 42 bytes

(λ(b)(map(λ(y)(count(λ(x)(= x y))b))b))

Try it online!

JavaScript (ES2021), 35 bytes (not quite reasonable I/O)

a=>a.map(n=>a[++(a[n]||=[0])[0],n])

Accept an array of 1 element array of negative numbers. Return an array of 1 element array...

f([-1, -2, -2, -1, -4, -8, -1]) // [[3], [2], [2], [3], [1], [1], [3]]
f([[-1], [-2], [-2], [-1], [-4], [-8], [-1]]) // [[3], [2], [2], [3], [1], [1], [3]]

Just consider input / output as column vectors...


JavaScript (ES2021), 42 bytes

Add an extra .flat() to make it reasonable would cost +7 bytes (42 bytes in total)

a=>a.map(n=>a[++(a[n]||=[0])[0],n]).flat()

That's too long.

Raku, 10 bytes

{.Bag{$_}}

Try it online!

.Bag generates a Bag (a set with multiplicity) from the input argument $_. Then {$_} slices into that Bag with the original list, producing a list of the multiplicities of the elements of that list, in order.

Ruby, 27 bytes

f=->*a{a.map{|e|a.count e}}

Testing:

p f[4,3,4]  #=> [2, 1, 2]

R, 26 bytes

ave(a,a<-scan(),FUN=table)

Try it online!

ave takes a vector x, an arbitrary number of grouping variables ..., and a function FUN, and replaces each element of x with the result of applying FUN to the group containing that element.

I've also found a number of 26 byte variants with FUN=sum; they differ only in the way they generate a vector of ones with length length(a).

ave(a^0,a<-scan(),FUN=sum)
ave(a,a<-scan(),FUN=sum)/a
ave(a|1,a<-scan(),FUN=sum)

Factor, 28 bytes

[ dup histogram substitute ]

Try it online!

It's a bit shorter than the version for squares:

[ dup [ '[ _ = ] count ] with map ]

Explanation:

It's a quotation (anonymous function) that takes a sequence from the data stack as input and leaves a sequence on the data stack as output. Assuming { 1 4 4 } is on the data stack when this quotation is called...

Wolfram Language (Mathematica), 12 bytes

Counts@#/@#&

Try it online!

05AB1E, 1 byte

¢

Try it online! Beats all other answers.

¢  # full program
¢  # number of times...
   # (implicit) each element in...
   # implicit input...
¢  # appears in...
   # implicit input
   # implicit output

APL(Dyalog Unicode), 6 bytes SBCS

+/∘.=⍨

Try it on APLgolf!

+/∘.=⍨  dfn submission
  ∘.=   product table using equality
     ⍨  applied to the input on the left and the right
+/      reduce by addition / sum

Scala, 22 bytes

a=>a.map(a count _.==)

Try it in Scastie!

MATL, 3 bytes

&=s

Try it online! Or verify all test cases.

Explanation

     % Implicit input: numeric row vector
&=   % Matrix of all pairwise equality comparisons
s    % Sum of each column
     % Implicit display

Vyxal, 2 bytes

vO

Try it Online!

Wow y'all using unicode in your golfing languages while I'm chilling in the ASCII zone.

Explained

vO  # vectorise count over the input
    # essentially, [input.count(n) for n in input]

05AB1E, 2 bytes

€¢

Try it online!

Explained

€¢   # [input.count(n) for n in input]

Python 2, 23 bytes

lambda l:map(l.count,l)

Try it online!

Pyth, 3 bytes

/LQ

Test suite

Explanation:

/LQ  | Full program
/LQQ | with implicit variables
-----+-------------------------------------
 L Q | replace each element d in input with
/ Q  | the count of d in input

Python 3, 26 bytes

lambda l:[*map(l.count,l)]

Try it online!

-5 bytes (indirectly) thanks to xnor!

Charcoal, 6 bytes

IEθ№θι

Try it online! Link is to verbose version of code. Explanation:

  θ     Input array
 E      Map over elements
   №    Count of
     ι  Current element in
    θ   Input arrray
I       Cast to string
        Implicitly print

JavaScript (ES6), 36 bytes

a=>a.map(x=>a.map(y=>t+=x==y,t=0)|t)

Try it online!

Haskell, 27 bytes

f a=[sum[1|y<-a,y==x]|x<-a]

Try it online!

Jelly, 2 bytes

ċⱮ

Try it online!

How it works

ċⱮ - Main link. Takes a list L on the left
 Ɱ - For each element in L
ċ  -   Count the times it appears in L