The Pythagorean theorem in certain symmetry classes of tensors