Background Info
I am interested in a better way of doing the following:
I want to find the weights of the following codewords (the weight of a codeword here can be defined as the number of nonzero entries in that codeword e.g the weight of the codeword (1,0,1,1) would be 3):
{{0,0,0,0},{0,0,0,1},{0,0,1,0},{0,0,1,1}} The weights of these codewords would be 0,1,1 and 2 respectively.
Let $A_{i}$ denote the number of codewords with weight $i$.
So for this example, there is one codeword of weight $0$ so $A_{0}=1$
There are two codewords of weight $1$, so $A_{1}=2$
There is one codeword of weight $2$, so $A_{2}=1$
My attempt
Define the codewords and their respective weights
In[1]= codewords = {{0, 0, 0, 0}, {1, 0, 0, 0}, {0, 1, 0, 0}, {1, 1, 0, 0}} In[2]= weights = Total[codewords[[#]]] & /@ Range[Length[codewords]] Out[1]= {{0, 0, 0, 0}, {1, 0, 0, 0}, {0, 1, 0, 0}, {1, 1, 0, 0}} Out[2]= {0, 1, 1, 2} Now define $A_{i}$ as being the number of codewords of weight $i$
In[3]= A0 = Length[If[weights[[#]] == 0, 0, Nothing] & /@ Range[Length[weights]]] In[4]= A1 = Length[If[weights[[#]] == 1, 1, Nothing] & /@ Range[Length[weights]]] In[5]= A2 = Length[If[weights[[#]] == 2, 2, Nothing] & /@ Range[Length[weights]]] Out[3]= 1 Out[4]= 2 Out[5]= 1 The above code works, but there must be a more elegant solution, perhaps one that doesn't need so much manual interference. If anyone has a better idea, please let me know!
Mapis that you don't need to keep track of indices yourself. So, in your solution, you can replaceweights = Total[codewords[[#]]] & /@ Range[Length[codewords]]withweights = Total /@ codewords$\endgroup$