當前位置: 首頁>>代碼示例>>Python>>正文


Python numpy.add方法代碼示例

本文整理匯總了Python中numpy.add方法的典型用法代碼示例。如果您正苦於以下問題:Python numpy.add方法的具體用法?Python numpy.add怎麽用?Python numpy.add使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在numpy的用法示例。


在下文中一共展示了numpy.add方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: BuildAdjacency

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import add [as 別名]
def BuildAdjacency(CMat, K):
    CMat = CMat.astype(float)
    CKSym = None
    N, _ = CMat.shape
    CAbs = np.absolute(CMat).astype(float)
    for i in range(0, N):
        c = CAbs[:, i]
        PInd = np.flip(np.argsort(c), 0)
        CAbs[:, i] = CAbs[:, i] / float(np.absolute(c[PInd[0]]))
    CSym = np.add(CAbs, CAbs.T).astype(float)
    if K != 0:
        Ind = np.flip(np.argsort(CSym, axis=0), 0)
        CK = np.zeros([N, N]).astype(float)
        for i in range(0, N):
            for j in range(0, K):
                CK[Ind[j, i], i] = CSym[Ind[j, i], i] / float(np.absolute(CSym[Ind[0, i], i]))
        CKSym = np.add(CK, CK.T)
    else:
        CKSym = CSym
    return CKSym 
開發者ID:abhinav4192,項目名稱:sparse-subspace-clustering-python,代碼行數:22,代碼來源:BuildAdjacency.py

示例2: geometric_brownian_motion_jump_diffusion_log_returns

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import add [as 別名]
def geometric_brownian_motion_jump_diffusion_log_returns(params: ModelParameters):
    """
    Constructs combines a geometric brownian motion process
    (log returns) with a jump diffusion process (log returns) to produce
    a sequence of gbm jump returns.

    Arguments:
        params : ModelParameters
            The parameters for the stochastic model.

    Returns:
        A GBM process with jumps in it
    """
    jump_diffusion = jump_diffusion_process(params)
    geometric_brownian_motion = geometric_brownian_motion_log_returns(params)
    return np.add(jump_diffusion, geometric_brownian_motion) 
開發者ID:tensortrade-org,項目名稱:tensortrade,代碼行數:18,代碼來源:heston.py

示例3: test_multi_step_adding

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import add [as 別名]
def test_multi_step_adding():

    a1 = Stream([1, 2, 3]).rename("a1")
    a2 = Stream([4, 5, 6]).rename("a2")

    t1 = BinOp(np.add)(a1, a2).rename("t1")
    t2 = BinOp(np.add)(t1, a2).rename("t2")

    feed = DataFeed([a1, a2, t1, t2])

    output = feed.next()
    assert output == {'a1': 1, 'a2': 4, 't1': 5, 't2': 9}

    feed = DataFeed([a1, a2, t2])

    output = feed.next()
    assert output == {'a1': 1, 'a2': 4, 't2': 9} 
開發者ID:tensortrade-org,項目名稱:tensortrade,代碼行數:19,代碼來源:test_feed.py

示例4: _rsp_findpeaks_outliers

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import add [as 別名]
def _rsp_findpeaks_outliers(rsp_cleaned, extrema, amplitude_min=0.3):

    # Only consider those extrema that have a minimum vertical distance to
    # their direct neighbor, i.e., define outliers in absolute amplitude
    # difference between neighboring extrema.
    vertical_diff = np.abs(np.diff(rsp_cleaned[extrema]))
    median_diff = np.median(vertical_diff)
    min_diff = np.where(vertical_diff > (median_diff * amplitude_min))[0]
    extrema = extrema[min_diff]

    # Make sure that the alternation of peaks and troughs is unbroken. If
    # alternation of sign in extdiffs is broken, remove the extrema that
    # cause the breaks.
    amplitudes = rsp_cleaned[extrema]
    extdiffs = np.sign(np.diff(amplitudes))
    extdiffs = np.add(extdiffs[0:-1], extdiffs[1:])
    removeext = np.where(extdiffs != 0)[0] + 1
    extrema = np.delete(extrema, removeext)
    amplitudes = np.delete(amplitudes, removeext)

    return extrema, amplitudes 
開發者ID:neuropsychology,項目名稱:NeuroKit,代碼行數:23,代碼來源:rsp_findpeaks.py

示例5: build_generator

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import add [as 別名]
def build_generator(self):

        model = Sequential()

        model.add(Dense(128 * 7 * 7, activation="relu", input_dim=self.latent_dim))
        model.add(Reshape((7, 7, 128)))
        model.add(BatchNormalization(momentum=0.8))
        model.add(UpSampling2D())
        model.add(Conv2D(128, kernel_size=3, padding="same"))
        model.add(Activation("relu"))
        model.add(BatchNormalization(momentum=0.8))
        model.add(UpSampling2D())
        model.add(Conv2D(64, kernel_size=3, padding="same"))
        model.add(Activation("relu"))
        model.add(BatchNormalization(momentum=0.8))
        model.add(Conv2D(1, kernel_size=3, padding="same"))
        model.add(Activation("tanh"))

        model.summary()

        noise = Input(shape=(self.latent_dim,))
        img = model(noise)

        return Model(noise, img) 
開發者ID:eriklindernoren,項目名稱:Keras-GAN,代碼行數:26,代碼來源:sgan.py

示例6: build_discriminator

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import add [as 別名]
def build_discriminator(self):

        model = Sequential()

        model.add(Conv2D(64, kernel_size=3, strides=2, input_shape=self.missing_shape, padding="same"))
        model.add(LeakyReLU(alpha=0.2))
        model.add(BatchNormalization(momentum=0.8))
        model.add(Conv2D(128, kernel_size=3, strides=2, padding="same"))
        model.add(LeakyReLU(alpha=0.2))
        model.add(BatchNormalization(momentum=0.8))
        model.add(Conv2D(256, kernel_size=3, padding="same"))
        model.add(LeakyReLU(alpha=0.2))
        model.add(BatchNormalization(momentum=0.8))
        model.add(Flatten())
        model.add(Dense(1, activation='sigmoid'))
        model.summary()

        img = Input(shape=self.missing_shape)
        validity = model(img)

        return Model(img, validity) 
開發者ID:eriklindernoren,項目名稱:Keras-GAN,代碼行數:23,代碼來源:context_encoder.py

示例7: build_discriminator

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import add [as 別名]
def build_discriminator(self):

        img = Input(shape=self.img_shape)

        model = Sequential()
        model.add(Conv2D(64, kernel_size=4, strides=2, padding='same', input_shape=self.img_shape))
        model.add(LeakyReLU(alpha=0.8))
        model.add(Conv2D(128, kernel_size=4, strides=2, padding='same'))
        model.add(LeakyReLU(alpha=0.2))
        model.add(InstanceNormalization())
        model.add(Conv2D(256, kernel_size=4, strides=2, padding='same'))
        model.add(LeakyReLU(alpha=0.2))
        model.add(InstanceNormalization())

        model.summary()

        img = Input(shape=self.img_shape)
        features = model(img)

        validity = Conv2D(1, kernel_size=4, strides=1, padding='same')(features)

        label = Flatten()(features)
        label = Dense(self.num_classes+1, activation="softmax")(label)

        return Model(img, [validity, label]) 
開發者ID:eriklindernoren,項目名稱:Keras-GAN,代碼行數:27,代碼來源:ccgan.py

示例8: build_encoder

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import add [as 別名]
def build_encoder(self):
        model = Sequential()

        model.add(Flatten(input_shape=self.img_shape))
        model.add(Dense(512))
        model.add(LeakyReLU(alpha=0.2))
        model.add(BatchNormalization(momentum=0.8))
        model.add(Dense(512))
        model.add(LeakyReLU(alpha=0.2))
        model.add(BatchNormalization(momentum=0.8))
        model.add(Dense(self.latent_dim))

        model.summary()

        img = Input(shape=self.img_shape)
        z = model(img)

        return Model(img, z) 
開發者ID:eriklindernoren,項目名稱:Keras-GAN,代碼行數:20,代碼來源:bigan.py

示例9: build_generator

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import add [as 別名]
def build_generator(self):
        model = Sequential()

        model.add(Dense(512, input_dim=self.latent_dim))
        model.add(LeakyReLU(alpha=0.2))
        model.add(BatchNormalization(momentum=0.8))
        model.add(Dense(512))
        model.add(LeakyReLU(alpha=0.2))
        model.add(BatchNormalization(momentum=0.8))
        model.add(Dense(np.prod(self.img_shape), activation='tanh'))
        model.add(Reshape(self.img_shape))

        model.summary()

        z = Input(shape=(self.latent_dim,))
        gen_img = model(z)

        return Model(z, gen_img) 
開發者ID:eriklindernoren,項目名稱:Keras-GAN,代碼行數:20,代碼來源:bigan.py

示例10: build_generator

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import add [as 別名]
def build_generator(self):

        model = Sequential()

        model.add(Dense(128 * 7 * 7, activation="relu", input_dim=self.latent_dim))
        model.add(Reshape((7, 7, 128)))
        model.add(BatchNormalization(momentum=0.8))
        model.add(UpSampling2D())
        model.add(Conv2D(128, kernel_size=3, padding="same"))
        model.add(Activation("relu"))
        model.add(BatchNormalization(momentum=0.8))
        model.add(UpSampling2D())
        model.add(Conv2D(64, kernel_size=3, padding="same"))
        model.add(Activation("relu"))
        model.add(BatchNormalization(momentum=0.8))
        model.add(Conv2D(self.channels, kernel_size=3, padding='same'))
        model.add(Activation("tanh"))

        gen_input = Input(shape=(self.latent_dim,))
        img = model(gen_input)

        model.summary()

        return Model(gen_input, img) 
開發者ID:eriklindernoren,項目名稱:Keras-GAN,代碼行數:26,代碼來源:infogan.py

示例11: build_generator

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import add [as 別名]
def build_generator(self):

        model = Sequential()

        model.add(Dense(128 * 7 * 7, activation="relu", input_dim=self.latent_dim))
        model.add(Reshape((7, 7, 128)))
        model.add(UpSampling2D())
        model.add(Conv2D(128, kernel_size=4, padding="same"))
        model.add(BatchNormalization(momentum=0.8))
        model.add(Activation("relu"))
        model.add(UpSampling2D())
        model.add(Conv2D(64, kernel_size=4, padding="same"))
        model.add(BatchNormalization(momentum=0.8))
        model.add(Activation("relu"))
        model.add(Conv2D(self.channels, kernel_size=4, padding="same"))
        model.add(Activation("tanh"))

        model.summary()

        noise = Input(shape=(self.latent_dim,))
        img = model(noise)

        return Model(noise, img) 
開發者ID:eriklindernoren,項目名稱:Keras-GAN,代碼行數:25,代碼來源:wgan.py

示例12: build_generator

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import add [as 別名]
def build_generator(self):

        model = Sequential()

        model.add(Dense(256, input_dim=self.latent_dim))
        model.add(LeakyReLU(alpha=0.2))
        model.add(BatchNormalization(momentum=0.8))
        model.add(Dense(512))
        model.add(LeakyReLU(alpha=0.2))
        model.add(BatchNormalization(momentum=0.8))
        model.add(Dense(1024))
        model.add(LeakyReLU(alpha=0.2))
        model.add(BatchNormalization(momentum=0.8))
        model.add(Dense(np.prod(self.img_shape), activation='tanh'))
        model.add(Reshape(self.img_shape))

        model.summary()

        noise = Input(shape=(self.latent_dim,))
        img = model(noise)

        return Model(noise, img) 
開發者ID:eriklindernoren,項目名稱:Keras-GAN,代碼行數:24,代碼來源:lsgan.py

示例13: build_discriminator

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import add [as 別名]
def build_discriminator(self):

        model = Sequential()

        model.add(Flatten(input_shape=self.img_shape))
        model.add(Dense(512))
        model.add(LeakyReLU(alpha=0.2))
        model.add(Dense(256))
        model.add(LeakyReLU(alpha=0.2))
        # (!!!) No softmax
        model.add(Dense(1))
        model.summary()

        img = Input(shape=self.img_shape)
        validity = model(img)

        return Model(img, validity) 
開發者ID:eriklindernoren,項目名稱:Keras-GAN,代碼行數:19,代碼來源:lsgan.py

示例14: build_discriminators

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import add [as 別名]
def build_discriminators(self):

        img1 = Input(shape=self.img_shape)
        img2 = Input(shape=self.img_shape)

        # Shared discriminator layers
        model = Sequential()
        model.add(Flatten(input_shape=self.img_shape))
        model.add(Dense(512))
        model.add(LeakyReLU(alpha=0.2))
        model.add(Dense(256))
        model.add(LeakyReLU(alpha=0.2))

        img1_embedding = model(img1)
        img2_embedding = model(img2)

        # Discriminator 1
        validity1 = Dense(1, activation='sigmoid')(img1_embedding)
        # Discriminator 2
        validity2 = Dense(1, activation='sigmoid')(img2_embedding)

        return Model(img1, validity1), Model(img2, validity2) 
開發者ID:eriklindernoren,項目名稱:Keras-GAN,代碼行數:24,代碼來源:cogan.py

示例15: build_generator

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import add [as 別名]
def build_generator(self):

        X = Input(shape=(self.img_dim,))

        model = Sequential()
        model.add(Dense(256, input_dim=self.img_dim))
        model.add(LeakyReLU(alpha=0.2))
        model.add(BatchNormalization(momentum=0.8))
        model.add(Dropout(0.4))
        model.add(Dense(512))
        model.add(LeakyReLU(alpha=0.2))
        model.add(BatchNormalization(momentum=0.8))
        model.add(Dropout(0.4))
        model.add(Dense(1024))
        model.add(LeakyReLU(alpha=0.2))
        model.add(BatchNormalization(momentum=0.8))
        model.add(Dropout(0.4))
        model.add(Dense(self.img_dim, activation='tanh'))

        X_translated = model(X)

        return Model(X, X_translated) 
開發者ID:eriklindernoren,項目名稱:Keras-GAN,代碼行數:24,代碼來源:dualgan.py


注:本文中的numpy.add方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。