votes up 1

t must be 1d, but t.ndim equals (param1).

Package:
scipy
github stars 8546
Exception Class:
ValueError

Raise code

        raise ValueError('x must not contain nonfinite values.')
    if not np.isfinite(y).all():
        raise ValueError('y must not contain nonfinite values.')
    n = nx + ny

    # check if t is valid
    if t.ndim > 1:
        raise ValueError('t must be 1d, but t.ndim equals {}.'.format(t.ndim))
    if np.less_equal(t, 0).any():
        raise ValueError('t must contain positive elements only.')

    # rescale t with semi-iqr as proposed in [1]; import iqr here to avoid
    # circular import
    from scipy.stats import iqr
    sigma = iqr(np.hstack((x, y))) / 2
😲  Walkingbet is Android app that pays you real bitcoins for a walking. Withdrawable real money bonus is available now, hurry up! 🚶

Ways to fix

votes up 1 votes down

The parameter t should be a 1D array.

Reproducing the error:

pipenv install numpy scipy

from scipy.stats._hypotests import epps_singleton_2samp
import numpy as np
x = np.array([-0.352.551.730.730.35,
                      2.690.46-0.94-0.3712.07])
y = np.array([-1.15-0.152.483.253.71,
                      4.295.007.748.388.60])


w, p = epps_singleton_2samp(x, y, t=[(0.40.8)])
print(w,p)

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-5-cbf81c898b13> in <module>()
      6                       4.29, 5.00, 7.74, 8.38, 8.60])
      7 
----> 8 w, p = epps_singleton_2samp(x, y, t=[(0.4, 0.8)])
      9 print(w,p)

/usr/local/lib/python3.7/dist-packages/scipy/stats/_hypotests.py in epps_singleton_2samp(x, y, t)
     96     # check if t is valid
     97     if t.ndim > 1:
---> 98         raise ValueError('t must be 1d, but t.ndim equals {}.'.format(t.ndim))
     99     if np.less_equal(t, 0).any():
    100         raise ValueError('t must contain positive elements only.')

ValueError: t must be 1d, but t.ndim equals 2.

Fixed:

from scipy.stats._hypotests import epps_singleton_2samp
import numpy as np
x = np.array([-0.352.551.730.730.35,
                      2.690.46-0.94-0.3712.07])
y = np.array([-1.15-0.152.483.253.71,
                      4.295.007.748.388.60])


w, p = epps_singleton_2samp(x, y, t=(0.40.8))
print(w,p)

15.163072195549608 0.004374674473820839

Aug 29, 2021 kellemnegasi answer
kellemnegasi 31.6k

Add a possible fix

Please authorize to post fix