Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9022191
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T05:26:36+00:00 2026-06-16T05:26:36+00:00

Is there a built-in function in scipy/numpy for getting the PMF of a Multinomial?

  • 0

Is there a built-in function in scipy/numpy for getting the PMF of a Multinomial? I’m not sure if binom generalizes in the correct way, e.g.

# Attempt to define multinomial with n = 10, p = [0.1, 0.1, 0.8]
rv = scipy.stats.binom(10, [0.1, 0.1, 0.8])
# Score the outcome 4, 4, 2
rv.pmf([4, 4, 2])

What is the correct way to do this? thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T05:26:37+00:00Added an answer on June 16, 2026 at 5:26 am

    There’s no built-in function that I know of, and the binomial probabilities do not generalize (you need to normalise over a different set of possible outcomes, since the sum of all the counts must be n which won’t be taken care of by independent binomials). However, it’s fairly straightforward to implement yourself, for example:

    import math
    
    class Multinomial(object):
      def __init__(self, params):
        self._params = params
    
      def pmf(self, counts):
        if not(len(counts)==len(self._params)):
          raise ValueError("Dimensionality of count vector is incorrect")
    
        prob = 1.
        for i,c in enumerate(counts):
          prob *= self._params[i]**counts[i]
    
        return prob * math.exp(self._log_multinomial_coeff(counts))
    
      def log_pmf(self,counts):
        if not(len(counts)==len(self._params)):
          raise ValueError("Dimensionality of count vector is incorrect")
    
        prob = 0.
        for i,c in enumerate(counts):
          prob += counts[i]*math.log(self._params[i])
    
        return prob + self._log_multinomial_coeff(counts)
    
      def _log_multinomial_coeff(self, counts):
        return self._log_factorial(sum(counts)) - sum(self._log_factorial(c)
                                                        for c in counts)
    
      def _log_factorial(self, num):
        if not round(num)==num and num > 0:
          raise ValueError("Can only compute the factorial of positive ints")
        return sum(math.log(n) for n in range(1,num+1))
    
    m = Multinomial([0.1, 0.1, 0.8])
    print m.pmf([4,4,2])
    
    >>2.016e-05
    

    My implementation of the multinomial coefficient is somewhat naive, and works in log space to prevent overflow. Also be aware that n is superfluous as a parameter, since it’s given by the sum of the counts (and the same parameter set works for any n). Furthermore, since this will quickly underflow for moderate n or large dimensionality, you’re better working in log space (logPMF provided here too!)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there any built-in function in Python3/Numpy which filters an array and returns indices
Is there a built-in php function or an easy way to insert an element
If there is any built-in function for getting random letters like RANDOM(low,high) we used
Is there a built-in php function, or a simple (efficient!) way to combine built-in
Is there a way to disable the standard built-in function of the Windows-Key (open
Is there a built in function or a way to query the size of
Is there a FFT-based 2D cross-correlation or convolution function built into scipy (or another
Is there a built-in function that converts a datetime.date object into a datetime.datetime object
Is there a built-in function for converting a string array into a dictionary of
Is there a built-in function for PHP for me to check whether two arrays

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.