def imag(self, newimag):
        """Setter for the imaginary part.

        This method is invoked by ``x.imag = other``.

        Parameters
        ----------
        newimag : array-like or scalar
            Values to be assigned to the imaginary part of this element.
        """
        try:
            iter(newimag)
        except TypeError:
            # `newimag` is not iterable, assume it can be assigned to
            # all indexed parts
            for part in self.parts:
                part.imag = newimag
            return

        if self.space.is_power_space:
            try:
                # Set same value in all parts
                for part in self.parts:
                    part.imag = newimag
            except (ValueError, TypeError):
                # Iterate over all parts and set them separately
                for part, new_im in zip(self.parts, newimag):
                    part.imag = new_im
                pass
        elif len(newimag) == len(self):
            for part, new_im in zip(self.parts, newimag):
                part.imag = new_im
        else:
            raise ValueError(
                'dimensions of the new imaginary part does not match the '
                'space, got element {} to set real part of {}}'
                ''.format(newimag, self))
Setter for the imaginary part.

        This method is invoked by ``x.imag = other``.

        Parameters
        ----------
        newimag : array-like or scalar
            Values to be assigned to the imaginary part of this element.