Reputation: 47
It seems that matplotlib will deprecate the cross_from_above
and cross_from_below
functions in the upcoming version 3.1
This is a shame as they're very useful tools for "returning the indices where a 1D array crosses a threshold from above/below". See current documentation at: https://matplotlib.org/api/mlab_api.html
I can't find any discussion of this online so wonder if there are replacement functions that I should be using instead for the same functionality?
Upvotes: 2
Views: 56
Reputation: 339580
There is no replacement for these functions. But they aren't very complicated. Here is the literal copy of the source code.
def cross_from_above(x, threshold):
"""
return the indices into *x* where *x* crosses some threshold from above.
"""
x = np.asarray(x)
ind = np.nonzero((x[:-1] >= threshold) & (x[1:] < threshold))[0]
if len(ind):
return ind+1
else:
return ind
and
def cross_from_below(x, threshold):
"""
return the indices into *x* where *x* crosses some threshold from below.
"""
x = np.asarray(x)
ind = np.nonzero((x[:-1] < threshold) & (x[1:] >= threshold))[0]
if len(ind):
return ind+1
else:
return ind
where np
is numpy
.
Essentially they both contain a single line of code, which is easy to replicate or modified in any actual use case.
Upvotes: 2