votes up 1

'df' must be greater than zero.

Package:
Exception Class:
ValueError

Raise code

            raise ValueError("Array 'cov' must be at most two-dimensional,"
                             " but cov.ndim = %d" % shape.ndim)

        # Process degrees of freedom.
        if df is None:
            df = 1
        elif df <= 0:
            raise ValueError("'df' must be greater than zero.")
        elif np.isnan(df):
            raise ValueError("'df' is 'nan' but must be greater than zero or 'np.inf'.")

        return dim, loc, shape, df


class multivariate_t_frozen(multi_rv_frozen):
😲 Agile task management is now easier than calling a taxi. #Tracklify

Ways to fix

votes up 2 votes down

df should be greater than 0.

Code to reproduce the exception:

from scipy.stats import multivariate_t
x = [0.45]
loc = [01]
shape = [10.1]
df = -7
multivariate_t.rvs(loc, shape, df)

---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-5-52c65fb6be1b> in <module>()  4 shape = [1, 0.1]  5 df = -7 ----> 6 multivariate_t.rvs(loc, shape, df) 
/usr/local/lib/python3.7/dist-packages/scipy/stats/_multivariate.py in rvs(self, loc, shape, df, size, random_state)  4070 # http://rjournal.github.io/archive/2013-2/hofert.pdf  4071 # -> 4072 dim, loc, shape, df = self._process_parameters(loc, shape, df)  4073 if random_state is not None:  4074 rng = check_random_state(random_state) 
/usr/local/lib/python3.7/dist-packages/scipy/stats/_multivariate.py in _process_parameters(self, loc, shape, df)  4154 df = 1  4155 elif df <= 0: -> 4156 raise ValueError("'df' must be greater than zero.")  4157 elif np.isnan(df):  4158 raise ValueError("'df' is 'nan' but must be greater than zero or 'np.inf'.") 
ValueError: 'df' must be greater than zero.

Fixed version of the code:

from scipy.stats import multivariate_t
x = [0.45]
loc = [01]
shape = [10.1]
df = 7
multivariate_t.rvs(loc, shape, df)

array([-0.50411888, 1.26230372])

Nov 25, 2021 kellemnegasi answer
kellemnegasi 18.4k

Add a possible fix

Please authorize to post fix