<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def linear_deform(template, displacement, out=None):
 """Linearized deformation of a template with a displacement field. The function maps a given template ``I`` and a given displacement field ``v`` to the new function ``x --> I(x + v(x))``. Parameters template : `DiscreteLpElement` Template to be deformed by a displacement field. displacement : element of power space of ``template.space`` Vector field (displacement field) used to deform the template. out : `numpy.ndarray`, optional Array to which the function values of the deformed template are written. It must have the same shape as ``template`` and a data type compatible with ``template.dtype``. Returns ------- deformed_template : `numpy.ndarray` Function values of the deformed template. If ``out`` was given, the returned object is a reference to it. Examples -------- Create a simple 1D template to initialize the operator and apply it to a displacement field. Where the displacement is zero, the output value is the same as the input value. In the 4-th point, the value is taken from 0.2 (one cell) to the left, i.e. 1.0. array([ 0., 0., 1., 1., 0.]) The result depends on the chosen interpolation. With 'linear' interpolation and an offset equal to half the distance between two points, 0.1, one gets the mean of the values. array([ 0. , 0. , 1. , 0.5, 0. ]) """

    image_pts = template.space.points()
    for i, vi in enumerate(displacement):
        image_pts[:, i] += vi.asarray().ravel()
    values = template.interpolation(image_pts.T, out=out, bounds_check=False)
    return values.reshape(template.space.shape)