Utilities/maths/math_utils.py
def turning_points(array):
	''' turning_points(array) -> min_indices, max_indices
	Finds the turning points within an 1D array and returns the indices of the minimum and 
	maximum turning points in two separate lists.
	'''
	idx_max, idx_min = [], []
	if (len(array) < 3):
		return idx_min, idx_max

	NEUTRAL, RISING, FALLING = range(3)

	def get_state(a, b):
		if a < b:
			return RISING
		if a > b:
			return FALLING
		return NEUTRAL

	ps = get_state(array[0], array[1])
	begin = 1
	for i in range(2, len(array)):
		s = get_state(array[i - 1], array[i])
		if s != NEUTRAL:
			if ps != NEUTRAL and ps != s:
				if s == FALLING:
					idx_max.append((begin + i - 1) // 2)
				else:
					idx_min.append((begin + i - 1) // 2)
			begin = i
			ps = s
	return idx_min, idx_max
 turning_points(array) -> min_indices, max_indices
	Finds the turning points within an 1D array and returns the indices of the minimum and 
	maximum turning points in two separate lists.
	
> min_indices, max_indices
Finds the turning points within an 1D array and returns the indices of the minimum and
maximum turning points in two separate lists.
> min_indices max_indices Finds the turning points within an 1D array and returns the indices of the minimum and maximum turning points in two separate lists .
def turning_points(array):
	idx_max, idx_min = [], []
	if (len(array) < 3):
		return idx_min, idx_max
	NEUTRAL, RISING, FALLING = range(3)
	def get_state(a, b):
		if a < b:
			return RISING
		if a > b:
			return FALLING
		return NEUTRAL
	ps = get_state(array[0], array[1])
	begin = 1
	for i in range(2, len(array)):
		s = get_state(array[i - 1], array[i])
		if s != NEUTRAL:
			if ps != NEUTRAL and ps != s:
				if s == FALLING:
					idx_max.append((begin + i - 1) // 2)
				else:
					idx_min.append((begin + i - 1) // 2)
			begin = i
			ps = s
	return idx_min, idx_max
def turning_points ( array ) : idx_max , idx_min = [ ] , [ ] if ( len ( array ) < 3 ) : return idx_min , idx_max NEUTRAL , RISING , FALLING = range ( 3 ) def get_state ( a , b ) : if a < b : return RISING if a > b : return FALLING return NEUTRAL ps = get_state ( array [ 0 ] , array [ 1 ] ) begin = 1 for i in range ( 2 , len ( array ) ) : s = get_state ( array [ i - 1 ] , array [ i ] ) if s != NEUTRAL : if ps != NEUTRAL and ps != s : if s == FALLING : idx_max . append ( ( begin + i - 1 ) // 2 ) else : idx_min . append ( ( begin + i - 1 ) // 2 ) begin = i ps = s return idx_min , idx_max
turning_points(array) -> min_indices, max_indices
Finds the turning points within an 1D array and returns the indices of the minimum and
maximum turning points in two separate lists.
turning_points ( array ) - > min_indices max_indices Finds the turning points within an 1D array and returns the indices of the minimum and maximum turning points in two separate lists .
''' turning_points(array) -> min_indices, max_indices
	Finds the turning points within an 1D array and returns the indices of the minimum and 
	maximum turning points in two separate lists.
	'''
array