Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 8
- -1
- -41
- -71
- -97
- -124
- -126
- -117
- -107
- -78
- -26
- 10
- 46
- 63
- 94
- 100
- 88
- 87
- 105
- 109
- 81
- 39
- 7
- -12
- -126
- 109
- 1
- 10
- 11
- 1
- a = [8, -1, -41, -71, -97, -124, -126, -117, -107, -78, -26, 10, 46, 63, 94, 100, 88, 87, 105, 109, 81, 39, 7, -12]
- def search_min(a):
- el_min = a[0]
- for elm in a[1:]:
- if elm < el_min:
- el_min = elm
- print("The minimum value in the list is: " + str(el_min))
- def search_max(a):
- el_max = a[0]
- for elm in a[1:]:
- if elm > el_max:
- el_max = elm
- print("The maximum value in the list is: " + str(el_max))
- search_min(a)
- search_max(a)
- import numpy as np
- import pandas as pd
- fn = r'C:Temp.data .txt'
- s = pd.read_csv(fn, header=None, squeeze=True)
- grp = s.groupby((np.sign(s).diff().fillna(0).ne(0)).cumsum())
- extremums = grp.apply(lambda x: x.abs().max() * np.sign(x[x.abs().idxmax()]))
- sizes = grp.count()
- In [103]: grp.agg([lambda x: x.abs().max() * np.sign(x[x.abs().idxmax()]), 'count'])
- .rename(columns={'<lambda>':'extremum'})
- Out[103]:
- extremum count
- 0
- 0 46 2
- 1 -316 29
- 2 148 31
- 3 -126 10
- 4 109 12
- 5 -168 33
- 6 41 5
- 7 -333 45
- 8 85 18
- 9 -123 17
- 10 70 14
- 11 -11 1
- 12 35 14
- 13 -97 18
- 14 190 75
- 15 -73 13
- import numpy as np
- import pandas as pd
- s = pd.Series([1,2,1,-4,-7,-2,-5,4,3,1,2,-1,-2,-3])
- extremums = s.groupby((np.sign(s).diff().fillna(0).ne(0)).cumsum())
- .apply(lambda x: x.abs().max() * np.sign(x[x.abs().idxmax()]))
- In [74]: print(extremums)
- 0 2
- 1 -7
- 2 4
- 3 -3
- dtype: int64
- In [75]: print(extremums.values)
- [ 2 -7 4 -3]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement