nudomarinero/wquantiles

'list' object has no attribute 'ndim'

Closed this issue · 1 comments

Hello,

I am trying to apply the following simple code


wquantiles.median([1,2,3,4,5], weights = [0.15, 0.1, 0.2, 0.3, 0.25])

Unfortunately, I have the following error:

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-12-1caff6aaa564> in <module>
      6 
      7 # example of the weighted median
----> 8 wquantiles.median([1,2,3,4,5], weights = [[0.15, 0.1, 0.2, 0.3, 0.25]])

/opt/conda/lib/python3.7/site-packages/wquantiles.py in median(data, weights)
     93     Alias for `quantile(data, weights, 0.5)`.
     94     """
---> 95     return quantile(data, weights, 0.5)

/opt/conda/lib/python3.7/site-packages/wquantiles.py in quantile(data, weights, quantile)
     75     """
     76     # TODO: Allow to specify the axis
---> 77     nd = data.ndim
     78     if nd == 0:
     79         TypeError("data must have at least one dimension")

AttributeError: 'list' object has no attribute 'ndim'

Could you help me please? I could not find any documentation.

Try to convert the input lists to numpy arrays first:
wquantiles.median(numpy.array([1,2,3,4,5]), weights = numpy.array([0.15, 0.1, 0.2, 0.3, 0.25]))
If it does not work please let me know.