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