Resize the shape of the given matrix