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


Python numpy.reciprocal方法代碼示例

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


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

示例1: update_rho

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import reciprocal [as 別名]
def update_rho(self, rho_new):
        """
        Update set-size parameter rho
        """
        if rho_new <= 0:
            raise ValueError("rho must be positive")

        # Update rho
        self.work.settings.rho = np.minimum(np.maximum(rho_new,
                                            RHO_MIN), RHO_MAX)

        # Update rho_vec and rho_inv_vec
        ineq_ind = np.where(self.work.constr_type == 0)
        eq_ind = np.where(self.work.constr_type == 1)
        self.work.rho_vec[ineq_ind] = self.work.settings.rho
        self.work.rho_vec[eq_ind] = RHO_EQ_OVER_RHO_INEQ * self.work.settings.rho
        self.work.rho_inv_vec = np.reciprocal(self.work.rho_vec)

        # Factorize KKT
        self.work.linsys_solver = linsys_solver(self.work) 
開發者ID:oxfordcontrol,項目名稱:osqp-python,代碼行數:22,代碼來源:_osqp.py

示例2: ComputeMassMatrixInfo

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import reciprocal [as 別名]
def ComputeMassMatrixInfo(self, M, formulation, fem_solver):
        """Computes the inverse of lumped mass matrix and so on
        """

        invM = None
        if formulation.fields == "electro_mechanics":
            if fem_solver.mass_type == "lumped":
                M = M.ravel()
                invM = np.zeros_like(M)
                invM[self.mechanical_dofs] = np.reciprocal(M[self.mechanical_dofs])
                M_mech = M[self.mechanical_dofs]
            else:
                M_mech = M[self.mechanical_dofs,:][:,self.mechanical_dofs]
        else:
            if fem_solver.mass_type == "lumped":
                M = M.ravel()
                M_mech = M
                invM = np.reciprocal(M)
            else:
                M_mech = M

        return M_mech, invM 
開發者ID:romeric,項目名稱:florence,代碼行數:24,代碼來源:StructuralDynamicIntegrator.py

示例3: forward

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import reciprocal [as 別名]
def forward(self, inputs):
        self.retain_inputs((0, 1, 2, 4))
        x, gamma, mean, var, gy = inputs
        expander = self.expander
        xp = backend.get_array_module(x)

        if self.inv_std is None or self.inv_var is None:
            self.inv_var = xp.reciprocal(var + self.eps)
            self.inv_std = xp.sqrt(self.inv_var, dtype=self.inv_var.dtype)

        self.gamma_over_std = gamma * self.inv_std
        x_hat = _x_hat(x, mean[expander], self.inv_std[expander])

        gx = self.gamma_over_std[expander] * gy
        gbeta = gy.sum(axis=self.axis, dtype=gamma.dtype)
        ggamma = (x_hat * gy).sum(axis=self.axis)
        gmean = -self.gamma_over_std * gbeta
        gvar = - 0.5 * self.inv_var * (
            gamma * ggamma).astype(var.dtype, copy=False)

        gx = gx.astype(dtype=x.dtype)

        self.retain_outputs((0, 1, 2, 3, 4))
        return gx, ggamma, gbeta, gmean, gvar 
開發者ID:chainer,項目名稱:chainer,代碼行數:26,代碼來源:batch_normalization.py

示例4: predict_proba

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import reciprocal [as 別名]
def predict_proba(X, classifier):
    """Probability estimation for OvR logistic regression.
    Positive class probabilities are computed as
    1. / (1. + np.exp(-classifier.decision_function(X)));
    multiclass is handled by normalizing that over all classes.
    """
    prob = np.dot(X, classifier['coef_'].T) + classifier['intercept_']
    prob = prob.ravel() if prob.shape[1] == 1 else prob
    prob *= -1
    np.exp(prob, prob)
    prob += 1
    np.reciprocal(prob, prob)
    if prob.ndim == 1:
        return np.vstack([1 - prob, prob]).T
    else:
        # OvR normalization, like LibLinear's predict_probability
        prob /= prob.sum(axis=1).reshape((prob.shape[0], -1))
        return prob 
開發者ID:ecohealthalliance,項目名稱:EpiTator,代碼行數:20,代碼來源:geoname_classifier.py

示例5: vector_normalize

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import reciprocal [as 別名]
def vector_normalize(v):
    """
    Normalise (Euclidean) the last axis of a numpy array

    :param v: numpy vector array, any dimension
    :return:  array normalized, 0 vectors will be np.nan

    .. versionadded:: 9.3.1
    """
    if v.ndim < 2:
        return np.array((1.,))
    vs = v.shape
    v = v.reshape((-1, v.shape[-1]))
    mag = np.linalg.norm(v, axis=1)
    mag[mag == 0.] = np.nan
    return (v.T * np.reciprocal(mag)).T.reshape(vs) 
開發者ID:GeosoftInc,項目名稱:gxpy,代碼行數:18,代碼來源:utility.py

示例6: l1_inverse

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import reciprocal [as 別名]
def l1_inverse(depth1,depth2):
    """
    Computes the l1 errors between inverses of two depth maps.
    Takes preprocessed depths (no nans, infs and non-positive values)

    depth1:  one depth map
    depth2:  another depth map

    Returns: 
        L1(log)

    """
    assert(np.all(np.isfinite(depth1) & np.isfinite(depth2) & (depth1 > 0) & (depth2 > 0)))
    diff = np.reciprocal(depth1) - np.reciprocal(depth2)
    num_pixels = float(diff.size)
    
    if num_pixels == 0:
        return np.nan
    else:
        return np.sum(np.absolute(diff)) / num_pixels 
開發者ID:lmb-freiburg,項目名稱:demon,代碼行數:22,代碼來源:metrics.py

示例7: compute_cooccurrence_constraint

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import reciprocal [as 別名]
def compute_cooccurrence_constraint(self, nodes):
        """
        Co-occurrence constraint as described in the paper.

        Parameters
        ----------
        nodes: np.array
            Nodes whose features are considered for change

        Returns
        -------
        np.array [len(nodes), D], dtype bool
            Binary matrix of dimension len(nodes) x D. A 1 in entry n,d indicates that
            we are allowed to add feature d to the features of node n.

        """

        words_graph = self.cooc_matrix.copy()
        D = self.X_obs.shape[1]
        words_graph.setdiag(0)
        words_graph = (words_graph > 0)
        word_degrees = np.sum(words_graph, axis=0).A1

        inv_word_degrees = np.reciprocal(word_degrees.astype(float) + 1e-8)

        sd = np.zeros([self.N])
        for n in range(self.N):
            n_idx = self.X_obs[n, :].nonzero()[1]
            sd[n] = np.sum(inv_word_degrees[n_idx.tolist()])

        scores_matrix = sp.lil_matrix((self.N, D))

        for n in nodes:
            common_words = words_graph.multiply(self.X_obs[n])
            idegs = inv_word_degrees[common_words.nonzero()[1]]
            nnz = common_words.nonzero()[0]
            scores = np.array([idegs[nnz == ix].sum() for ix in range(D)])
            scores_matrix[n] = scores
        self.cooc_constraint = sp.csr_matrix(scores_matrix - 0.5 * sd[:, None] > 0) 
開發者ID:danielzuegner,項目名稱:nettack,代碼行數:41,代碼來源:nettack.py

示例8: test_blocked

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import reciprocal [as 別名]
def test_blocked(self):
        # test alignments offsets for simd instructions
        # alignments for vz + 2 * (vs - 1) + 1
        for dt, sz in [(np.float32, 11), (np.float64, 7), (np.int32, 11)]:
            for out, inp1, inp2, msg in _gen_alignment_data(dtype=dt,
                                                            type='binary',
                                                            max_size=sz):
                exp1 = np.ones_like(inp1)
                inp1[...] = np.ones_like(inp1)
                inp2[...] = np.zeros_like(inp2)
                assert_almost_equal(np.add(inp1, inp2), exp1, err_msg=msg)
                assert_almost_equal(np.add(inp1, 2), exp1 + 2, err_msg=msg)
                assert_almost_equal(np.add(1, inp2), exp1, err_msg=msg)

                np.add(inp1, inp2, out=out)
                assert_almost_equal(out, exp1, err_msg=msg)

                inp2[...] += np.arange(inp2.size, dtype=dt) + 1
                assert_almost_equal(np.square(inp2),
                                    np.multiply(inp2, inp2),  err_msg=msg)
                # skip true divide for ints
                if dt != np.int32 or (sys.version_info.major < 3 and not sys.py3kwarning):
                    assert_almost_equal(np.reciprocal(inp2),
                                        np.divide(1, inp2),  err_msg=msg)

                inp1[...] = np.ones_like(inp1)
                np.add(inp1, 2, out=out)
                assert_almost_equal(out, exp1 + 2, err_msg=msg)
                inp2[...] = np.ones_like(inp2)
                np.add(2, inp2, out=out)
                assert_almost_equal(out, exp1 + 2, err_msg=msg) 
開發者ID:Frank-qlu,項目名稱:recruit,代碼行數:33,代碼來源:test_scalarmath.py

示例9: reciprocal

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import reciprocal [as 別名]
def reciprocal(self):
        return self.power(-1)

    ############################################## 
開發者ID:FabriceSalvaire,項目名稱:PySpice,代碼行數:6,代碼來源:Unit.py

示例10: period

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import reciprocal [as 別名]
def period(self):
        r""" Return the period :math:`T = \frac{1}{f}`. """
        return self.reciprocal()

    ############################################## 
開發者ID:FabriceSalvaire,項目名稱:PySpice,代碼行數:7,代碼來源:Unit.py

示例11: test_reciprocal

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import reciprocal [as 別名]
def test_reciprocal(input_data):
    expected_output = np.reciprocal(input_data)
    node = onnx.helper.make_node('Reciprocal', inputs=['x'], outputs=['y'])
    ng_results = run_node(node, [input_data])
    assert np.allclose(ng_results, [expected_output]) 
開發者ID:NervanaSystems,項目名稱:ngraph-onnx,代碼行數:7,代碼來源:test_ops_unary.py

示例12: test_blocked

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import reciprocal [as 別名]
def test_blocked(self):
        # test alignments offsets for simd instructions
        # alignments for vz + 2 * (vs - 1) + 1
        for dt, sz in [(np.float32, 11), (np.float64, 7)]:
            for out, inp1, inp2, msg in _gen_alignment_data(dtype=dt,
                                                            type='binary',
                                                            max_size=sz):
                exp1 = np.ones_like(inp1)
                inp1[...] = np.ones_like(inp1)
                inp2[...] = np.zeros_like(inp2)
                assert_almost_equal(np.add(inp1, inp2), exp1, err_msg=msg)
                assert_almost_equal(np.add(inp1, 1), exp1 + 1, err_msg=msg)
                assert_almost_equal(np.add(1, inp2), exp1, err_msg=msg)

                np.add(inp1, inp2, out=out)
                assert_almost_equal(out, exp1, err_msg=msg)

                inp2[...] += np.arange(inp2.size, dtype=dt) + 1
                assert_almost_equal(np.square(inp2),
                                    np.multiply(inp2, inp2),  err_msg=msg)
                assert_almost_equal(np.reciprocal(inp2),
                                    np.divide(1, inp2),  err_msg=msg)

                inp1[...] = np.ones_like(inp1)
                inp2[...] = np.zeros_like(inp2)
                np.add(inp1, 1, out=out)
                assert_almost_equal(out, exp1 + 1, err_msg=msg)
                np.add(1, inp2, out=out)
                assert_almost_equal(out, exp1, err_msg=msg) 
開發者ID:abhisuri97,項目名稱:auto-alt-text-lambda-api,代碼行數:31,代碼來源:test_scalarmath.py

示例13: __call__

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import reciprocal [as 別名]
def __call__(self, image, mask):
        mean = np.reshape(np.array(self.mean, dtype=image.dtype), [1, 1, self.channel])
        std = np.reshape(np.array(self.std, dtype=image.dtype), [1, 1, self.channel])
        denominator = np.reciprocal(std, dtype=image.dtype)

        new_image = (image - mean) * denominator
        new_mask = mask

        return new_image, new_mask 
開發者ID:Media-Smart,項目名稱:vedaseg,代碼行數:11,代碼來源:transforms.py

示例14: compute_cooccurrence_constraint

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import reciprocal [as 別名]
def compute_cooccurrence_constraint(self, nodes):
        """
        Co-occurrence constraint as described in the paper.

        Parameters
        ----------
        nodes: np.array
            Nodes whose features are considered for change

        Returns
        -------
        np.array [len(nodes), D], dtype bool
            Binary matrix of dimension len(nodes) x D. A 1 in entry n,d indicates that
            we are allowed to add feature d to the features of node n.

        """

        words_graph = self.cooc_matrix.copy()
        D = self.modified_features.shape[1]
        words_graph.setdiag(0)
        words_graph = (words_graph > 0)
        word_degrees = np.sum(words_graph, axis=0).A1

        inv_word_degrees = np.reciprocal(word_degrees.astype(float) + 1e-8)

        sd = np.zeros([self.nnodes])
        for n in range(self.nnodes):
            n_idx = self.modified_features[n, :].nonzero()[1]
            sd[n] = np.sum(inv_word_degrees[n_idx.tolist()])

        scores_matrix = sp.lil_matrix((self.nnodes, D))

        for n in nodes:
            common_words = words_graph.multiply(self.modified_features[n])
            idegs = inv_word_degrees[common_words.nonzero()[1]]
            nnz = common_words.nonzero()[0]
            scores = np.array([idegs[nnz == ix].sum() for ix in range(D)])
            scores_matrix[n] = scores
        self.cooc_constraint = sp.csr_matrix(scores_matrix - 0.5 * sd[:, None] > 0) 
開發者ID:DSE-MSU,項目名稱:DeepRobust,代碼行數:41,代碼來源:nettack.py

示例15: _batch_normalization

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import reciprocal [as 別名]
def _batch_normalization(self, x, mean, variance, bias, scale,
                           variance_epsilon):
    inv = np.reciprocal(np.sqrt(variance + variance_epsilon))
    if scale is not None:
      inv *= scale
    return x * inv + (bias - mean * inv if bias is not None else -mean * inv) 
開發者ID:onnx,項目名稱:onnx-tensorflow,代碼行數:8,代碼來源:test_node.py


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