IndexError: boolean index does not match indexed array by size 0
My code worked fine until I updated Numpy to 1.13.1. Now I am getting the following error:
IndexError: boolean index did not match indexed array along dimension 0; dimension is 5 but corresponding boolean dimension is 4
... which is thrown into this line:
m = arr[np.diff(np.cumsum(arr) >= sum(arr) * i)]
I can't wrap my head around me. Any suggestions?
Here's my sample code:
a = [1,2,3,4,5] l = [0.85,0.90] s = sorted(a, reverse = False) arr = np.array(s) for i in l: m = arr[np.diff(np.cumsum(arr) >= sum(arr) * i)]
+3
source to share
1 answer
np.diff
is one element less than data_array.
The exit shape is the same as with the exception of the axis, where the dimension is n less.
I'm using Numpy 1.11, IndexError
we get a instead VisibleDeprecationWarning
. So my guess is that using the wrong size is no longer allowed.
You need to define what behavior you want, eg. start at the second element or remove the last one:
arr = np.array([1,2,3,4,5])
arr2 = arr[:-1]
m = arr2[np.diff(np.cumsum(arr) >= sum(arr))]
arr3 = arr[1:]
m = arr3[np.diff(np.cumsum(arr) >= sum(arr))]
+3
source to share