function tr = ndtrace(A)
	% trace of 3x3x sz array
	% returns array of size sz containing trace of each page of A
	s		= size(A);
	if length(s) < 3
		s	= [1 1];
	elseif length(s) < 4
		s	= [s(3) 1];
	else
		s	= s(3:end);
	end
		
	tr		= reshape(A(1,1,:) + A(2,2,:) + A(3,3,:), s);
end