ladiesman - 1 year ago 89

Python Question

I'm trying to extend a base class (scipy.stats.multivariate_normal) but I'm having some difficulty with calling

`super`

`__init__`

`from scipy.stats import multivariate_normal`

class MVGaussian(multivariate_normal):

def __init__(self, *args, **kwargs): # I want base class to handle all the arguments

super(MVGaussian, self).__init__(*args,**kwargs)

# def myMethod ...

I always get

`TypeError: __init__() takes from 1 to 2 positional arguments but 4 were given`

I've also tried

`super().__init__(*args,**kwargs)`

`multivariate_normal.__init__(*args, **kwargs)`

Recommended for you: Get network issues from **WhatsUp Gold**. **Not end users.**

Answer Source

You're trying to subclass `multivariate_normal`

, but it isn't a class, it's an instance of a class that has defined a `__call__`

method:

```
In [24]: isinstance(multivariate_normal, scipy.stats._multivariate.multivariate_normal_gen)
Out[24]: True
```

You'll have to subclass `scipy.stats._multivariate.multivariate_normal_gen`

and make an instance of your class for it to behave like `multivariate_normal`

:

```
from scipy.stats._multivariate import multivariate_normal_gen
class MVGaussian(multivariate_normal_gen):
def __init__(self, *args, **kwargs):
super(MVGaussian, self).__init__(*args,**kwargs)
mv_gaussian = MVGaussian()
```

Look at the source code for more info: https://github.com/scipy/scipy/blob/8a6cf90358c40ab525dc4de5ffa74e4eed163eed/scipy/stats/_multivariate.py#L220-L430

Recommended from our users: **Dynamic Network Monitoring from WhatsUp Gold from IPSwitch**. ** Free Download**