Get image data in :py:class:`numpy:numpy.ndarray` form.

        Note that if the image data is already in the correct format
        this can be a null operation.

        When converting to limited range types (``numpy.uint8``,
        ``numpy.uint16``) the data is clipped (limited) to the range.

        :keyword numpy.dtype dtype: What
            :py:class:`~numpy:numpy.dtype` the data should be in, e.g.
            ``numpy.float32``. If ``dtype`` is ``None`` then no
            conversion will be done.

        :keyword bool copy: Forces a copy of the data to be made, even
            if it is already an :py:class:`numpy:numpy.ndarray` with the
            requested dtype.

        :return: The image data as :py:class:`numpy:numpy.ndarray`.

        :rtype: :py:class:`numpy.ndarray`

def as_numpy(self, dtype=None, copy=False):
        """Get image data in :py:class:`numpy:numpy.ndarray` form.

        Note that if the image data is already in the correct format
        this can be a null operation.

        When converting to limited range types (``numpy.uint8``,
        ``numpy.uint16``) the data is clipped (limited) to the range.

        :keyword numpy.dtype dtype: What
            :py:class:`~numpy:numpy.dtype` the data should be in, e.g.
            ``numpy.float32``. If ``dtype`` is ``None`` then no
            conversion will be done.

        :keyword bool copy: Forces a copy of the data to be made, even
            if it is already an :py:class:`numpy:numpy.ndarray` with the
            requested dtype.

        :return: The image data as :py:class:`numpy:numpy.ndarray`.

        :rtype: :py:class:`numpy.ndarray`

        """
        if isinstance(self.data, numpy.ndarray):
            result = self.data
        elif isinstance(self.data, PIL.Image.Image):
            if self.data.mode == 'P':
                data = self.data.convert()
            else:
                data = self.data
            if data.mode == 'F':
                result = numpy.array(data, dtype=numpy.float32)
            elif data.mode == 'I':
                result = numpy.array(data, dtype=numpy.int32)
            elif dtype is not None:
                result = numpy.array(data, dtype=dtype)
            else:
                result = numpy.array(data, dtype=pt_float)
            copy = False
        else:
            raise RuntimeError(
                'Cannot convert "%s" to numpy' % self.data.__class__.__name__)
        if dtype is not None and result.dtype != dtype:
            if dtype == numpy.uint8:
                result = result.clip(0, 255)
            elif dtype == numpy.uint16:
                result = result.clip(0, 2**16 - 1)
            result = result.astype(dtype)
            copy = False
        if copy:
            result = result.copy()
        return result