Skip to content
Advertisement

Error in Float can’t be interpreted as an integer in old code

I am trying to reuse this old function generated by a former employee and the company I now work at and am receiving the error “TypeError: object of type <class ‘float’> cannot be safely interpreted as an integer.” I thought I could fix it quite easily with integer division // but that doesn’t seem to be fixing the issue.

def ricker(f, length, dt): # function for Ricker wavelet
    t = np.linspace(-length / 2, (length-dt) / 2, length / dt)
    y = (1. - 2.*(np.pi**2)*(f**2)*(t**2))*np.exp(-(np.pi**2)*(f**2)*(t**2))
    return t, y

def synthy(rho,v,f,dt,v_scale,h_scale):
    Z = rho*v 
    scaled_dt = v_scale * 1.0/v[:,0] 
    tdr = 2 * np.cumsum(scaled_dt)
    t = np.arange(tdr.min(), tdr.max(), dt)
    tw, w = ricker (f=f, length = 0.99*len(t)*dt, dt = dt)
    
    Stemp = [] 
    lengths = [] 
    
   
    for i in range(rho.shape[1]):
        scaled_dt = v_scale * 1.0/v[:,i] 
        tdr = 2 * np.cumsum(scaled_dt) 
        t = np.arange(tdr.min(), tdr.max(), dt)
        Z_t = np.interp(x = t, xp = tdr, fp = Z[:,i])
        RC_t = (Z_t[1:] - Z_t[:-1]) / (Z_t[1:] + Z_t[:-1]) 
        synth = np.convolve(RC_t, w, mode='same') 
        Stemp.append(synth)
        lengths.append(len(synth))
        
    S = np.zeros((min(lengths),rho.shape[1]))
    for i in range(rho.shape[1]):
        S[:,i] = Stemp[i][:min(lengths)]

    
    return S, fig, w, tw

S, fig, w, tw = synthy(rho,v,f=100,dt=0.0001,v_scale=v_scale,h_scale=h_scale)

Advertisement

Answer

numpy.linspace requires an integer for its third parameter:

    t = np.linspace(-length / 2, (length-dt) / 2, int(length / dt))
User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement