Add same_value and last_same_value
This commit is contained in:
parent
ecc8ac804e
commit
3c0ece6688
1 changed files with 20 additions and 0 deletions
20
utils.py
20
utils.py
|
@ -206,6 +206,26 @@ def last_consecutive( list_ ):
|
||||||
else: # if inside the consecutive list and last element, every element is consecutive
|
else: # if inside the consecutive list and last element, every element is consecutive
|
||||||
break
|
break
|
||||||
return i
|
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 ):
|
def rotate( image , angle ):
|
||||||
"""
|
"""
|
||||||
rotate the following image by the given angle
|
rotate the following image by the given angle
|
||||||
|
|
Loading…
Reference in a new issue