How to use the numpy.exp function in numpy

To help you get started, we’ve selected a few numpy examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github chainer / chainer / tests / chainer_tests / distributions_tests / test_one_hot_categorical.py View on Github external
def setUp_configure(self):
        from scipy import stats
        self.dist = distributions.OneHotCategorical
        self.scipy_dist = stats.multinomial

        self.test_targets = set([
            'batch_shape', 'event_shape', 'mean', 'sample'])

        n = numpy.ones(self.shape).astype(numpy.int32)
        p = numpy.random.normal(
            size=self.shape+(self.k,)).astype(numpy.float32)
        p = numpy.exp(p)
        p /= p.sum(axis=-1, keepdims=True)
        self.n, self.p = n, p
        self.params = {'p': p}
        self.scipy_params = {'n': n, 'p': p}

        self.continuous = False
        self.event_shape = (self.k,)
github loyalzc / transfer_learning / JDA / JDA.py View on Github external
if self.kernel == 'linear':
            if x2 is not None:
                K = np.dot(x2, x1.T)
            else:
                K = np.dot(x1, x1.T)
        elif self.kernel == 'rbf':
            if x2 is not None:
                n2 = np.shape(x2)[0]
                sum_x2 = np.sum(np.multiply(x2, x2), axis=1)
                sum_x2 = sum_x2.reshape((len(sum_x2), 1))
                K = np.exp(-1 * (np.tile(np.sum(np.multiply(x1, x1), axis=1).T, (n2, 1)) + np.tile(sum_x2, (1, n1))
                                 - 2 * np.dot(x2, x1.T)) / (dim * 2 * self.kernel_param))
            else:
                P = np.sum(np.multiply(x1, x1), axis=1)
                P = P.reshape((len(P), 1))
                K = np.exp(-1 * (np.tile(P.T, (n1, 1)) + np.tile(P, (1, n1)) - 2 * np.dot(x1, x1.T)) / (dim * 2 * self.kernel_param))
        # more kernels can be added
        return K
github linkerlin / MLRaptor / expfam / util / MLUtil.py View on Github external
def logsoftev2softev( logSoftEv, axis=1):
  lognormC = np.max( logSoftEv, axis)
  if axis==0:
    logSoftEv = logSoftEv - lognormC[np.newaxis,:]
  elif axis==1:
    logSoftEv = logSoftEv - lognormC[:,np.newaxis]
  SoftEv = np.exp( logSoftEv )
  return SoftEv, lognormC
github kastnerkyle / speech_density / midify.py View on Github external
if htk:
        return 700.0 * (10.0**(mels / 2595.0) - 1.0)

    # Fill in the linear scale
    f_min = 0.0
    f_sp = 200.0 / 3
    freqs = f_min + f_sp * mels

    # And now the nonlinear scale
    min_log_hz = 1000.0                         # beginning of log region (Hz)
    min_log_mel = (min_log_hz - f_min) / f_sp   # same (Mels)
    logstep = np.log(6.4) / 27.0                # step size for log region
    log_t = (mels >= min_log_mel)

    freqs[log_t] = min_log_hz * np.exp(logstep * (mels[log_t] - min_log_mel))

    return freqs
github convexengineering / gpkit / gpkit / tools / autosweep.py View on Github external
def posy_at(self, posy, value):
        """Logspace interpolates between sols to get posynomial values.

        No guarantees, just like a regular sweep.
        """
        if value < self.bounds[0] or value > self.bounds[1]:
            raise ValueError("query value is outside bounds.")
        bst = self.min_bst(value)
        lo, hi = bst.bounds
        loval, hival = [sol(posy) for sol in bst.sols]
        lo, hi, loval, hival = np.log(list(map(mag, [lo, hi, loval, hival])))
        interp = (hi-np.log(value))/float(hi-lo)
        return np.exp(interp*loval + (1-interp)*hival)
github python-acoustics / python-acoustics / acoustics / standards / iso_9613_1_1993.py View on Github external
"""
    Attenuation coefficient :math:`\\alpha` describing atmospheric absorption in dB/m for the specified ``frequency``.

    :param pressure: Ambient pressure :math:`T`
    :param temperature: Ambient temperature :math:`T`
    :param reference_pressure: Reference pressure :math:`p_{ref}`
    :param reference_temperature: Reference temperature :math:`T_{ref}`
    :param relaxation_frequency_nitrogen: Relaxation frequency of nitrogen :math:`f_{r,N}`.
    :param relaxation_frequency_oxygen: Relaxation frequency of oxygen :math:`f_{r,O}`.
    :param frequency: Frequencies to calculate :math:`\\alpha` for.

    """
    return 8.686 * frequency**2.0 * (
        (1.84 * 10.0**(-11.0) * (reference_pressure / pressure) * (temperature / reference_temperature)**
         (0.5)) + (temperature / reference_temperature)**
        (-2.5) * (0.01275 * np.exp(-2239.1 / temperature) * (relaxation_frequency_oxygen +
                                                             (frequency**2.0 / relaxation_frequency_oxygen))**
                  (-1.0) + 0.1068 * np.exp(-3352.0 / temperature) *
                  (relaxation_frequency_nitrogen + (frequency**2.0 / relaxation_frequency_nitrogen))**(-1.0)))
github flatironinstitute / CaImAn / caiman / motion_correction.py View on Github external
shifts = shifts[::-1]
        nc, nr = np.shape(src_freq)
        Nr = ifftshift(np.arange(-np.fix(nr/2.), np.ceil(nr/2.)))
        Nc = ifftshift(np.arange(-np.fix(nc/2.), np.ceil(nc/2.)))
        Nr, Nc = np.meshgrid(Nr, Nc)
        Greg = src_freq * np.exp(1j * 2 * np.pi *
                                 (-shifts[0] * 1. * Nr / nr - shifts[1] * 1. * Nc / nc))
    else:
        #shifts = np.array([*shifts[:-1][::-1],shifts[-1]])
        shifts = np.array(list(shifts[:-1][::-1]) + [shifts[-1]])
        nc, nr, nd = np.array(np.shape(src_freq), dtype=float)
        Nr = ifftshift(np.arange(-np.fix(nr / 2.), np.ceil(nr / 2.)))
        Nc = ifftshift(np.arange(-np.fix(nc / 2.), np.ceil(nc / 2.)))
        Nd = ifftshift(np.arange(-np.fix(nd / 2.), np.ceil(nd / 2.)))
        Nr, Nc, Nd = np.meshgrid(Nr, Nc, Nd)
        Greg = src_freq * np.exp(-1j * 2 * np.pi *
                                 (-shifts[0] * Nr / nr - shifts[1] * Nc / nc -
                                  shifts[2] * Nd / nd))

    Greg = Greg.dot(np.exp(1j * diffphase))
    if is3D:
        new_img = np.real(np.fft.ifftn(Greg))
    else:
        Greg = np.dstack([np.real(Greg), np.imag(Greg)])
        new_img = ifftn(Greg)[:, :, 0]

    if border_nan is not False:
        max_w, max_h, min_w, min_h = 0, 0, 0, 0
        max_h, max_w = np.ceil(np.maximum(
            (max_h, max_w), shifts[:2])).astype(np.int)
        min_h, min_w = np.floor(np.minimum(
            (min_h, min_w), shifts[:2])).astype(np.int)
github wmingwei / restricted-boltzmann-machine-deep-belief-network-deep-boltzmann-machine-in-pytorch / RBM / ais.py View on Github external
def logmeanexp(x, axis=None):
    
    x = np.asmatrix(x)
    if not axis:
        n = len(x)
    else:
        n = x.shape[axis]
    
    x_max = x.max(axis)
    return (x_max + np.log(np.exp(x-x_max).sum(axis)) - np.log(n)).A
github dm6718 / RITSAR / ritsar / imgTools.py View on Github external
#Remove linear trend
        t = np.arange(0,nsamples)
        slope, intercept, r_value, p_value, std_err = linregress(t,phi)
        line = slope*t+intercept
        phi = phi-line
        rms.append(np.sqrt(np.mean(phi**2)))
        
        if win == 'auto':
            if rms[iii]<0.1:
                break
        
        #Apply correction
        phi2 = np.tile(np.array([phi]).T,(1,nsamples))
        IMG_af = sig.ift(img_af, ax=0)
        IMG_af = IMG_af*np.exp(-1j*phi2)
        img_af = sig.ft(IMG_af, ax=0)
        
        #Store phase
        af_ph += phi    
       
    fig = plt.figure(figsize = (12,10))
    ax1 = fig.add_subplot(2,2,1)
    ax1.set_title('original')
    ax1.imshow(10*np.log10(np.abs(img)/np.abs(img).max()), cmap = cm.Greys_r)
    ax2 = fig.add_subplot(2,2,2)
    ax2.set_title('autofocused')
    ax2.imshow(10*np.log10(np.abs(img_af)/np.abs(img_af).max()), cmap = cm.Greys_r)
    ax3 = fig.add_subplot(2,2,3)
    ax3.set_title('rms phase error vs. iteration')
    plt.ylabel('Phase (radians)')
    ax3.plot(rms)