<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def subtract(self, val):
 """ Subtract a constant value or an image from all images. Parameters val : int, float, or ndarray Value to subtract. """

        if isinstance(val, ndarray):
            if val.shape != self.value_shape:
                raise Exception('Cannot subtract image with dimensions %s '
                                'from images with dimension %s' % (str(val.shape), str(self.value_shape)))

        return self.map(lambda x: x - val, value_shape=self.value_shape)