<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def upsample(time_series, scaling_factor):
 """Upsample using linear interpolation The function uses replication of the value at edges Parameters time_series : ndarray Input signal scaling_factor : float The factor to upsample with Returns ts_out : ndarray The upsampled signal """

    Ns0 = np.size(time_series)
    Ns  = np.int(np.floor(np.size(time_series)*scaling_factor))
    ts_out = np.zeros((Ns,1), dtype='float64')
    for k in range(0,Ns):
        cpos  = int(np.min([Ns0-1,np.max([0.,(k+0.5)/scaling_factor-0.5])]))
        cfrac = cpos-np.floor(cpos)
        cind  = int(np.floor(cpos))
        #print "cpos=%f cfrac=%f cind=%d", (cpos,cfrac,cind)
        if cfrac>0:
            ts_out[k]=time_series[cind]*(1-cfrac)+time_series[cind+1]*cfrac
        else:
            ts_out[k]=time_series[cind]
        
    return ts_out