Skip to content Skip to sidebar Skip to footer

Instance Of Scipy.stats.rv_discrete Subclass Throws Error On Pmf() Method

I want to create a subsclass of scipy.stats.rv_discrete to add some additional methods. However, when I try to access the pmf() method of the subclass, an error is raised. Please s

Solution 1:

@josef-pkt's answer on github is given below:

going through the regular subclassing creates a rv_sample class and doesn't init the correct class

the following works for me with 0.18.1 (which I have open right now)

from scipy.stats._distn_infrastructure import rv_sample

classsubc_rv_discrete(rv_sample):

    def__new__(cls, *args, **kwds):
        returnsuper(subc_rv_discrete, cls).__new__(cls)

xk = [0,1,2,3]
pk = [0.1, 0.2, 0.3, 0.4]

inst = subc_rv_discrete(values=(xk, pk))
print(inst.pmf(xk))
print(inst.__class__)

maybe this will be fixed in further scipy releases...

Post a Comment for "Instance Of Scipy.stats.rv_discrete Subclass Throws Error On Pmf() Method"