I am computing the pmf theoretically in Python. here is the code.
>>> a_coin = np.array([0,1])
>>> three_coins = np.array(np.meshgrid(a_coin,a_coin,a_coin)).T.reshape(-1,3)
>>> heads = np.sum(three_coins, axis = 1)
>>> df = pd.DataFrame({'heads': heads, 'prob': 1/8})
>>> np.array(df.groupby('heads').sum()['prob'])
array([0.125, 0.375, 0.375, 0.125])
this piece of code is simulating 1 toss of 3 fair coins. the possible outcomes is {0,1,2,3}. last line of code compute the probability for each of the possible outcomes respectively.
I have to put 10 'a_coin' in np.meshgrid(a_coin,...,a_coin) if i want to compute the pmf for tossing 10 fair coins, which seems to be boring and inefficient.
the question is, is there an more efficient way to do this in python or R?