scikit-hep/awkward-0.x

TypeError when using array.mean(weights)

marinang opened this issue · 2 comments

Hello when I do

eff = awkward.fromiter([0.66922095, 0.62967431, 0.66882649, 0.73115299, 0.76491228, 0.7925368,
 0.80567108, 0.75731822, 0.74576271, 0.75884956])
err = awkward.fromiter([0.01681407, 0.01677153, 0.01262797, 0.01043851, 0.00888083, 0.00750265,
 0.00769369, 0.01317376, 0.02142619, 0.02012114])

eff.mean(1/err*2)

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-25-15b803a33766> in <module>
----> 1 eff.mean(1/err*2)

~/anaconda3/envs/tfn2/lib/python3.7/site-packages/numpy/core/_methods.py in _mean(a, axis, dtype, out, keepdims)
    136 
    137     is_float16_result = False
--> 138     rcount = _count_reduce_items(arr, axis)
    139     # Make this warning show up first
    140     if rcount == 0:

~/anaconda3/envs/tfn2/lib/python3.7/site-packages/numpy/core/_methods.py in _count_reduce_items(arr, axis)
     55     items = 1
     56     for ax in axis:
---> 57         items *= arr.shape[ax]
     58     return items
     59 

TypeError: only integer scalar arrays can be converted to a scalar index

This was working before, I guess this is due to a change in NumPy. I can use np.average instead.

I see. Not to derail your analysis too much, but you might want to consider installing awkward1 and doing

>>> import awkward1 as ak
>>> eff1 = ak.from_awkward0(eff)
>>> eff1.mean()

You can zero-copy convert back and forth between Awkward0 and Awkward1, and Awkward1 won't suffer from the sensitivity to NumPy that Awkward0 has (because these functions are directly implemented, not through NumPy).

See also ak.mean documentation; all of the functions have been documented.

Okay great I will do that thanks :)