Write an algorithm to square the elements of a given 2D matrix using a map or in-place transformation.