I suppose the problem you are facing is that the size of your block nis a float, not an integer:
>>> A = np.arange(10)
# float block size
>>> np.add.reduceat(A, np.arange(0, A.shape[0], 5.0), axis=0)
# TypeError: Cannot cast array data from dtype('float64') to dtype('int64')
# according to the rule 'safe'
# integer block size
>>> np.add.reduceat(A, np.arange(0, A.shape[0], 5), axis=0)
# array([10, 35])
numpy.add.reduceatan array of integer indices is required, but numpy.arange(0, A.shape[0], 5.0)returns an array of float64 values.
source
share