My code was working fine until I updated Numpy to 1.13.1. Now I get 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 at this line:
m = arr[np.diff(np.cumsum(arr) >= sum(arr) * i)]
I can't seem to wrap my head around it. Any suggestions?
Here is 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)]
np.diff
is one element smaller than data_array.
The shape of the output is the same as a except along axis where the dimension is smaller by n.
numpy.diff
I am using Numpy 1.11, instead of an IndexError
I get a VisibleDeprecationWarning
. So I guess using an incorrect size is no longer tolerated.
You need to define which behaviour you want, e.g. start at the second element, or remove the last:
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))]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With