votes up 1

x and y must contain at least two observations.

Package:
scipy
github stars 8546
Exception Class:
ValueError

Raise code

""" 
    chosen significance level in this example.

    """
    xa = np.sort(np.asarray(x))
    ya = np.sort(np.asarray(y))

    if xa.size <= 1 or ya.size <= 1:
        raise ValueError('x and y must contain at least two observations.')
    if xa.ndim > 1 or ya.ndim > 1:
        raise ValueError('The samples must be one-dimensional.')
    if method not in ['auto', 'exact', 'asymptotic']:
        raise ValueError('method must be either auto, exact or asymptotic.')

    nx = len(xa)
    ny = len(ya)

Ways to fix

votes up 1 votes down

The length of the array x and y must be at least 2.

Steps to reproduce the error:

pipenv install scipy

import numpy as np
from scipy import stats
x = np.random.rand(1)
y = np.random.rand(1)
res = stats.cramervonmises_2samp(x, y, method='asymptotic')

---------------------------------------------------------------------------

ValueError                                Traceback (most recent call last)

<ipython-input-1-f9ea598a437b> in <module>()
      3 x = np.random.rand(1)
      4 y = np.random.rand(1)
----> 5 res = stats.cramervonmises_2samp(x, y, method='asymptotic')


/usr/local/lib/python3.7/dist-packages/scipy/stats/_hypotests.py in cramervonmises_2samp(x, y, method)
   1388 
   1389     if xa.size <= 1 or ya.size <= 1:
-> 1390         raise ValueError('x and y must contain at least two observations.')
   1391     if xa.ndim > 1 or ya.ndim > 1:
   1392         raise ValueError('The samples must be one-dimensional.')


ValueError: x and y must contain at least two observations.

Fixed:

import numpy as np
from scipy import stats
x = np.random.rand(2)
y = np.random.rand(2)
res = stats.cramervonmises_2samp(x, y, method='asymptotic')
Oct 13, 2021 kellemnegasi answer
kellemnegasi 13.5k

Add a possible fix

Please authorize to post fix