当前位置: 首页>>代码示例>>Python>>正文


Python numpy.setdiff1d方法代码示例

本文整理汇总了Python中numpy.setdiff1d方法的典型用法代码示例。如果您正苦于以下问题:Python numpy.setdiff1d方法的具体用法?Python numpy.setdiff1d怎么用?Python numpy.setdiff1d使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在numpy的用法示例。


在下文中一共展示了numpy.setdiff1d方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: add_intercept

# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import setdiff1d [as 别名]
def add_intercept(self, X):
        """Add 1's to data as last features."""
        # Data shape
        N, D = X.shape

        # Check if there's not already an intercept column
        if np.any(np.sum(X, axis=0) == N):

            # Report
            print('Intercept is not the last feature. Swapping..')

            # Find which column contains the intercept
            intercept_index = np.argwhere(np.sum(X, axis=0) == N)

            # Swap intercept to last
            X = X[:, np.setdiff1d(np.arange(D), intercept_index)]

        # Add intercept as last column
        X = np.hstack((X, np.ones((N, 1))))

        # Append column of 1's to data, and increment dimensionality
        return X, D+1 
开发者ID:wmkouw,项目名称:libTLDA,代码行数:24,代码来源:tcpr.py

示例2: test_one_hot

# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import setdiff1d [as 别名]
def test_one_hot():
    """Check if one_hot returns correct label matrices."""
    # Generate label vector
    y = np.hstack((np.ones((10,))*0,
                   np.ones((10,))*1,
                   np.ones((10,))*2))

    # Map to matrix
    Y, labels = one_hot(y)

    # Check for only 0's and 1's
    assert len(np.setdiff1d(np.unique(Y), [0, 1])) == 0

    # Check for correct labels
    assert np.all(labels == np.unique(y))

    # Check correct shape of matrix
    assert Y.shape[0] == y.shape[0]
    assert Y.shape[1] == len(labels) 
开发者ID:wmkouw,项目名称:libTLDA,代码行数:21,代码来源:test_util.py

示例3: dfs_trunk

# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import setdiff1d [as 别名]
def dfs_trunk(sim, A,alpha = 0.99, QUERYKNN = 10, maxiter = 8, K = 100, tol = 1e-3):
    qsim = sim_kernel(sim).T
    sortidxs = np.argsort(-qsim, axis = 1)
    for i in range(len(qsim)):
        qsim[i,sortidxs[i,QUERYKNN:]] = 0
    qsims = sim_kernel(qsim)
    W = sim_kernel(A)
    W = csr_matrix(topK_W(W, K))
    out_ranks = []
    t =time()
    for i in range(qsims.shape[0]):
        qs =  qsims[i,:]
        tt = time() 
        w_idxs, W_trunk = find_trunc_graph(qs, W, 2);
        Wn = normalize_connection_graph(W_trunk)
        Wnn = eye(Wn.shape[0]) - alpha * Wn
        f,inf = s_linalg.minres(Wnn, qs[w_idxs], tol=tol, maxiter=maxiter)
        ranks = w_idxs[np.argsort(-f.reshape(-1))]
        missing = np.setdiff1d(np.arange(A.shape[1]), ranks)
        out_ranks.append(np.concatenate([ranks.reshape(-1,1), missing.reshape(-1,1)], axis = 0))
    #print time() -t, 'qtime'
    out_ranks = np.concatenate(out_ranks, axis = 1)
    return out_ranks 
开发者ID:ducha-aiki,项目名称:manifold-diffusion,代码行数:25,代码来源:diffussion.py

示例4: set_diff

# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import setdiff1d [as 别名]
def set_diff(ar1, ar2):
    """Find the set difference of two index arrays.
    Return the unique values in ar1 that are not in ar2.

    Parameters
    ----------
    ar1: utils.Index
        Input index array.

    ar2: utils.Index
        Input comparison index array.

    Returns
    -------
    setdiff:
        Array of values in ar1 that are not in ar2.
    """
    ar1_np = ar1.tonumpy()
    ar2_np = ar2.tonumpy()
    setdiff = np.setdiff1d(ar1_np, ar2_np)
    setdiff = toindex(setdiff)
    return setdiff 
开发者ID:dmlc,项目名称:dgl,代码行数:24,代码来源:utils.py

示例5: cross_validation_folds

# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import setdiff1d [as 别名]
def cross_validation_folds(n, k=5):
    if n % k != 0:
        skip = int(np.floor(float(n)/float(k)))
    else:
        skip = n/k

    ind = np.arange(n)
    np.random.shuffle(ind)

    train_ind = dict()
    val_ind = dict()
    for i in range(k):
        if i == k-1: # Use the rest of the examples
            val = ind[skip*i:]
        else:
            val = ind[skip*i:skip*(i+1)]

        train = np.setdiff1d(ind, val_ind)

        val_ind[i] = val
        train_ind[i] = train

    return train_ind, val_ind 
开发者ID:bdol,项目名称:bdol-ml,代码行数:25,代码来源:data_utils.py

示例6: focus

# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import setdiff1d [as 别名]
def focus(self, lines):
        '''
        focus to target lines

        Args:
            lines (list): the target lines to put up.
        '''
        alllines = range(self.num_bit)
        pin = NodeBrush('pin')
        old_positions = []
        for i in range(self.num_bit):
            old_positions.append(self.gate(pin, i))

        lmap = np.append(lines, np.setdiff1d(alllines, lines))
        self.x += 0.8
        pins = []
        for opos, j in zip(old_positions, lmap):
            pi = Pin(self.get_position(j))
            self.node_dict[j].append(pi)
            self.edge >> (opos, pi)
            pins.append(pi)
        return pins 
开发者ID:GiggleLiu,项目名称:viznet,代码行数:24,代码来源:circuit.py

示例7: _parallel_predict_log_proba

# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import setdiff1d [as 别名]
def _parallel_predict_log_proba(estimators, estimators_features, X, n_classes):
    """Private function used to compute log probabilities within a job."""
    n_samples = X.shape[0]
    log_proba = np.empty((n_samples, n_classes))
    log_proba.fill(-np.inf)
    all_classes = np.arange(n_classes, dtype=np.int)

    for estimator, features in zip(estimators, estimators_features):
        log_proba_estimator = estimator.predict_log_proba(X[:, features])

        if n_classes == len(estimator.classes_):
            log_proba = np.logaddexp(log_proba, log_proba_estimator)

        else:
            log_proba[:, estimator.classes_] = np.logaddexp(
                log_proba[:, estimator.classes_],
                log_proba_estimator[:, range(len(estimator.classes_))])

            missing = np.setdiff1d(all_classes, estimator.classes_)
            log_proba[:, missing] = np.logaddexp(log_proba[:, missing],
                                                 -np.inf)

    return log_proba 
开发者ID:PacktPublishing,项目名称:Mastering-Elasticsearch-7.0,代码行数:25,代码来源:bagging.py

示例8: inverse_transform

# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import setdiff1d [as 别名]
def inverse_transform(self, y):
        """Transform labels back to original encoding.

        Parameters
        ----------
        y : numpy array of shape [n_samples]
            Target values.

        Returns
        -------
        y : numpy array of shape [n_samples]
        """
        check_is_fitted(self, 'classes_')
        y = column_or_1d(y, warn=True)
        # inverse transform of empty array is empty array
        if _num_samples(y) == 0:
            return np.array([])

        diff = np.setdiff1d(y, np.arange(len(self.classes_)))
        if len(diff):
            raise ValueError(
                    "y contains previously unseen labels: %s" % str(diff))
        y = np.asarray(y)
        return self.classes_[y] 
开发者ID:PacktPublishing,项目名称:Mastering-Elasticsearch-7.0,代码行数:26,代码来源:label.py

示例9: remove_intercept

# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import setdiff1d [as 别名]
def remove_intercept(self, X):
        """Remove 1's from data as last features."""
        # Data shape
        N, D = X.shape

        # Find which column contains the intercept
        intercept_index = []
        for d in range(D):
            if np.all(X[:, d] == 0):
                intercept_index.append(d)

        # Remove intercept columns
        X = X[:, np.setdiff1d(np.arange(D), intercept_index)]

        return X, D-len(intercept_index) 
开发者ID:wmkouw,项目名称:libTLDA,代码行数:17,代码来源:tcpr.py

示例10: test_predict

# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import setdiff1d [as 别名]
def test_predict():
    """Test for making predictions."""
    X = rnd.randn(10, 2)
    y = np.hstack((-np.ones((5,)), np.ones((5,))))
    Z = rnd.randn(10, 2) + 1
    clf = ImportanceWeightedClassifier()
    clf.fit(X, y, Z)
    u_pred = clf.predict(Z)
    labels = np.unique(y)
    assert len(np.setdiff1d(np.unique(u_pred), labels)) == 0 
开发者ID:wmkouw,项目名称:libTLDA,代码行数:12,代码来源:test_iw.py

示例11: test_predict

# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import setdiff1d [as 别名]
def test_predict():
    """Test for making predictions."""
    X = rnd.randn(10, 2)
    y = np.hstack((-np.ones((5,)), np.ones((5,))))
    Z = rnd.randn(10, 2) + 1
    clf = TransferComponentClassifier()
    clf.fit(X, y, Z)
    u_pred = clf.predict(Z)
    labels = np.unique(y)
    assert len(np.setdiff1d(np.unique(u_pred), labels)) == 0 
开发者ID:wmkouw,项目名称:libTLDA,代码行数:12,代码来源:test_tca.py

示例12: test_predict_semi

# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import setdiff1d [as 别名]
def test_predict_semi():
    """Test for making predictions."""
    X = rnd.randn(10, 2)
    y = np.hstack((np.zeros((5,)), np.ones((5,))))
    Z = rnd.randn(10, 2) + 1
    u = np.array([[0, 0], [9, 1]])
    clf = SemiSubspaceAlignedClassifier()
    clf.fit(X, y, Z, u)
    u_pred = clf.predict(Z)
    labels = np.unique(y)
    assert len(np.setdiff1d(np.unique(u_pred), labels)) == 0 
开发者ID:wmkouw,项目名称:libTLDA,代码行数:13,代码来源:test_suba.py

示例13: test_predict

# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import setdiff1d [as 别名]
def test_predict():
    """Test for making predictions."""
    X = rnd.randn(10, 2)
    y = np.hstack((np.zeros((5,)), np.ones((5,))))
    Z = rnd.randn(10, 2) + 1
    clf = RobustBiasAwareClassifier()
    clf.fit(X, y, Z)
    u_pred = clf.predict(Z)
    labels = np.unique(y)
    assert len(np.setdiff1d(np.unique(u_pred), labels)) == 0 
开发者ID:wmkouw,项目名称:libTLDA,代码行数:12,代码来源:test_rba.py

示例14: test_predict

# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import setdiff1d [as 别名]
def test_predict():
    """Test for making predictions."""
    X = np.vstack((rnd.randn(5, 2), rnd.randn(5, 2)+1))
    y = np.hstack((np.zeros((5,)), np.ones((5,))))
    Z = np.vstack((rnd.randn(5, 2)-1, rnd.randn(5, 2)+2))
    clf = TargetContrastivePessimisticClassifier(l2=0.1)
    clf.fit(X, y, Z)
    u_pred = clf.predict(Z)
    labels = np.unique(y)
    assert len(np.setdiff1d(np.unique(u_pred), labels)) == 0 
开发者ID:wmkouw,项目名称:libTLDA,代码行数:12,代码来源:test_tcpr.py

示例15: test_init

# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import setdiff1d [as 别名]
def test_init():
    """Test for object type."""
    clf = StructuralCorrespondenceClassifier()
    assert type(clf) == StructuralCorrespondenceClassifier
    assert not clf.is_trained


# def test_fit():
#     """Test for fitting the model."""
#     X = np.vstack((rnd.randn(5, 2), rnd.randn(5, 2)+1))
#     y = np.hstack((np.zeros((5,)), np.ones((5,))))
#     Z = np.vstack((rnd.randn(5, 2)-1, rnd.randn(5, 2)+2))
#     clf = StructuralCorrespondenceClassifier(l2=1.0)
#     clf.fit(X, y, Z)
#     assert clf.is_trained


# def test_predict():
#     """Test for making predictions."""
#     X = np.vstack((rnd.randn(5, 2), rnd.randn(5, 2)+1))
#     y = np.hstack((np.zeros((5,)), np.ones((5,))))
#     Z = np.vstack((rnd.randn(5, 2)-1, rnd.randn(5, 2)+2))
#     clf = StructuralCorrespondenceClassifier(l2=1.0)
#     clf.fit(X, y, Z)
#     u_pred = clf.predict(Z)
#     labels = np.unique(y)
#     assert len(np.setdiff1d(np.unique(u_pred), labels)) == 0 
开发者ID:wmkouw,项目名称:libTLDA,代码行数:29,代码来源:test_scl.py


注:本文中的numpy.setdiff1d方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。