say that I have a (40,20,30) numpy array and that I have a function that after some work will return half of the input array along a selected input axis. Is there an automatic way to do so ? I would like to avoid such an ugly code:
def my_function(array,axis=0):
...
if axis == 0:
return array[:array.shape[0]/2,:,:] --> (20,20,30) array
elif axis = 1:
return array[:,:array.shape[1]/2,:] --> (40,10,30) array
elif axis = 2:
return array[:,:,:array.shape[2]/2] --> (40,20,15) array
thanks for your help
Eric