I have a numpy array like below:
JavaScript
x
2
1
[12,544,73,56,30,84,34,29,78,22,73,23,98,83,35,62,52,94,44,67]
2
In this data there are 20 numbers and they are divided in 4 groups with 5 numbers in each group. so for ex.
JavaScript
1
3
1
12,544,73,56,30
2
84,34,29,78,22 etc.
3
I want to find out the maximum number from each group and store them in a list. Like:
JavaScript
1
2
1
sol=[544,84,98,94]
2
I am very new to python please help.
Advertisement
Answer
try by splitting 1st then find out the max.
JavaScript
1
4
1
x = np.array([12,544,73,56,30,84,34,29,78,22,73,23,98,83,35,62,52,94,44,67])
2
n = 4
3
res = np.array(np.array_split(x, n)).max(axis=1)
4
res:
JavaScript
1
2
1
array([544, 84, 98, 94])
2