diff --git a/utils.py b/utils.py index fc2fe6d..d3f7ead 100644 --- a/utils.py +++ b/utils.py @@ -206,6 +206,26 @@ def last_consecutive( list_ ): else: # if inside the consecutive list and last element, every element is consecutive break return i +def same_value( list_ ): + """ + divide a sorted list of integer by same value part + """ + if not isinstance( list_ , list ) and not isinstance( list_ , np.ndarray ): + raise ValueError( 'list_ must be a list, ' + type( list_ ) + ' given' ) + if len( list_ ) == 0: + return list_ + index = last_same_value( list_ ) + if index == len( list_ ) - 1: + return [ list_ ] + return same_value( list_[ : index + 1 ] ) + same_value( list_[ index + 1 : ] ) +def last_same_value( list_ ): + """ + return the last index of the first same value list + """ + if not isinstance( list_ , list ) and not isinstance( list_ , np.ndarray ): + raise ValueError( 'list_ must be a list, ' + type( list_ ) + ' given' ) + value = list_[0] + return np.argwhere( list_ == value ).max() def rotate( image , angle ): """ rotate the following image by the given angle