Numpy Slice by Value. There Has to be a Better Way!!!
I am trying to slice an array by the value it contains rather than it’s index. Basically I need to cut off everything after the last value in an array that is below a certain number and everything up to the first value that is above a certain certain number. The code can be written as: _____________________________________ Idx = range(np.min(np.where(y > 1.)), np.max(np.where(y < 6.))) _____________________________________ Here is some code that does that. The slice function does the slicing and I think it is too big and complicated. Its only in a function so I can test other options with the three test cases(in the dictionary) I couldn’t add a photo but if you go to my posts I posted a photo that shows what this line of code filters out of the dataset I am trying to work with. Is there a better way to do this??? Maybe in pandas? https://code.sololearn.com/cXIqhHHuH9gg/?ref=app