- import numpy as np
- def maxpooling(a):
- result=[]
- for k in range(3):
- result_channel=[]
- for i in range(0,10,2):
- result_row=[]
- for j in range(0,10,2):
- b=a[k,i:i+2,j:j+2]
- ans=np.max(b)
- result_row.append(ans)
- result_channel.append(result_row)
- result.append(result_channel)
- return np.array(result)
- a=np.array([i for i in range(300)])
- a=a.reshape((3,10,10))
- print(maxpooling(a))