Please I am a bit new to Python and it has been nice, I could comment that python is very sexy till I needed to shift content of a 4x4 matrix which I want to u
Thanks to all this is what I later use
def justify(a, direction):
mask = a>0
justified_mask = numpy.sort(mask,0) if direction == 'up' or direction =='down' else numpy.sort(mask, 1)
if direction == 'up':
justified_mask = justified_mask[::-1]
if direction =='left':
justified_mask = justified_mask[:,::-1]
if direction =='right':
justified_mask = justified_mask[::-1, :]
out = numpy.zeros_like(a)
out.T[justified_mask.T] = a.T[mask.T]
return out