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


Python numpy.c_方法代码示例

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


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

示例1: _add_bias

# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import c_ [as 别名]
def _add_bias(self, X):
        """add bias to list

        Args:
        x_vs [[float]] Array: vec to add bias

        Returns:
        [float]: added vec

        Examples:
        >>> e = ELM(10, 3)
        >>> e._add_bias(np.array([[1,2,3], [1,2,3]]))
        array([[1., 2., 3., 1.],
               [1., 2., 3., 1.]])
        """

        return np.c_[X, np.ones(X.shape[0])] 
开发者ID:masaponto,项目名称:Python-ELM,代码行数:19,代码来源:elm.py

示例2: fetch

# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import c_ [as 别名]
def fetch(self, n_tr, n_val, n_test, seed=0):
        x, y = self.load()
        
        # split data
        x_tr, x_val, y_tr, y_val = train_test_split(
            x, y, train_size=n_tr, test_size=n_val+n_test, random_state=seed)
        x_val, x_test, y_val, y_test = train_test_split(
            x_val, y_val, train_size=n_val, test_size=n_test, random_state=seed+1)
        
        # process x
        if self.normalize:
            scaler = StandardScaler()
            scaler.fit(x_tr)
            x_tr = scaler.transform(x_tr)
            x_val = scaler.transform(x_val)
            x_test = scaler.transform(x_test)
        if self.append_one:
            x_tr = np.c_[x_tr, np.ones(n_tr)]
            x_val = np.c_[x_val, np.ones(n_val)]
            x_test = np.c_[x_test, np.ones(n_test)]
        
        return (x_tr, y_tr), (x_val, y_val), (x_test, y_test) 
开发者ID:sato9hara,项目名称:sgd-influence,代码行数:24,代码来源:DataModule.py

示例3: show_classification_areas

# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import c_ [as 别名]
def show_classification_areas(X, Y, lr):
    x_min, x_max = X[:, 0].min() - .5, X[:, 0].max() + .5
    y_min, y_max = X[:, 1].min() - .5, X[:, 1].max() + .5
    xx, yy = np.meshgrid(np.arange(x_min, x_max, 0.02), np.arange(y_min, y_max, 0.02))
    Z = lr.predict(np.c_[xx.ravel(), yy.ravel()])

    Z = Z.reshape(xx.shape)
    plt.figure(1, figsize=(30, 25))
    plt.pcolormesh(xx, yy, Z, cmap=plt.cm.Pastel1)

    # Plot also the training points
    plt.scatter(X[:, 0], X[:, 1], c=np.abs(Y - 1), edgecolors='k', cmap=plt.cm.coolwarm)
    plt.xlabel('X')
    plt.ylabel('Y')

    plt.xlim(xx.min(), xx.max())
    plt.ylim(yy.min(), yy.max())
    plt.xticks(())
    plt.yticks(())

    plt.show() 
开发者ID:PacktPublishing,项目名称:Fundamentals-of-Machine-Learning-with-scikit-learn,代码行数:23,代码来源:1logistic_regression.py

示例4: test_blockdiag_GMM_train_and_convert

# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import c_ [as 别名]
def test_blockdiag_GMM_train_and_convert(self):
        jnt = np.random.rand(100, 20)
        gmm_tr = GMMTrainer(n_mix=4, n_iter=100, covtype='block_diag')
        gmm_tr.train(jnt)

        gmm_cv = GMMConvertor(
            n_mix=4, covtype='block_diag', gmmmode=None)
        gmm_cv.open_from_param(gmm_tr.param)

        data = np.random.rand(200, 5)
        sddata = np.c_[data, delta(data)]
        odata = gmm_cv.convert(sddata, cvtype='mlpg')
        odata = gmm_cv.convert(sddata, cvtype='mmse')
        assert data.shape == odata.shape

        # test for singlepath
        Ajnt = np.random.rand(100, 120)
        Bjnt = np.random.rand(100, 140)
        gmm_tr.estimate_responsibility(jnt)
        Aparam = gmm_tr.train_singlepath(Ajnt)
        Bparam = gmm_tr.train_singlepath(Bjnt)
        assert np.allclose(Aparam.weights_, Bparam.weights_) 
开发者ID:k2kobayashi,项目名称:sprocket,代码行数:24,代码来源:test_diagGMM.py

示例5: test_GMM_train_and_convert

# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import c_ [as 别名]
def test_GMM_train_and_convert(self):
        jnt = np.random.rand(100, 20)
        gmm_tr = GMMTrainer(n_mix=4, n_iter=100, covtype='full')
        gmm_tr.train(jnt)

        data = np.random.rand(200, 5)
        sddata = np.c_[data, delta(data)]
        gmm_cv = GMMConvertor(
            n_mix=4, covtype='full', gmmmode=None)
        gmm_cv.open_from_param(gmm_tr.param)

        odata = gmm_cv.convert(sddata, cvtype='mlpg')
        odata = gmm_cv.convert(sddata, cvtype='mmse')
        assert data.shape == odata.shape

        # test for singlepath
        Ajnt = np.random.rand(100, 120)
        Bjnt = np.random.rand(100, 140)
        gmm_tr.estimate_responsibility(jnt)
        Aparam = gmm_tr.train_singlepath(Ajnt)
        Bparam = gmm_tr.train_singlepath(Bjnt)
        assert np.allclose(Aparam.weights_, Bparam.weights_) 
开发者ID:k2kobayashi,项目名称:sprocket,代码行数:24,代码来源:test_GMM.py

示例6: align_data

# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import c_ [as 别名]
def align_data(org_data, tar_data, twf):
    """Get aligned joint feature vector

    Paramters
    ---------
    orgdata : array, shape (`T_org`, `dim_org`)
        Acoustic feature vector of original speaker
    tardata : array, shape (`T_tar`, `dim_tar`)
        Acoustic feature vector of target speaker
    twf : array, shape (`2`, `T`)
        Time warping function between original and target

    Returns
    -------
    jdata : array, shape (`T_new` `dim_org + dim_tar`)
        Joint feature vector between source and target

    """

    jdata = np.c_[org_data[twf[0]], tar_data[twf[1]]]
    return jdata 
开发者ID:k2kobayashi,项目名称:sprocket,代码行数:23,代码来源:twf.py

示例7: static_delta

# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import c_ [as 别名]
def static_delta(data, win=[-1.0, 1.0, 0]):
    """Calculate static and delta component

    Parameters
    ----------
    data : array, shape (`T`, `dim`)
        Array of static matrix sequence.
    win: array, optional, shape (`3`)
        The shape of window matrix.
        Default set to [-1.0, 1.0, 0].

    Returns
    -------
    sddata: array, shape (`T`, `dim*2`)
        Array static and delta matrix sequence.

    """

    sddata = np.c_[data, delta(data, win)]
    return sddata 
开发者ID:k2kobayashi,项目名称:sprocket,代码行数:22,代码来源:delta.py

示例8: testC_

# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import c_ [as 别名]
def testC_(self):
        r = mt.c_[mt.array([1, 2, 3]), mt.array([4, 5, 6])]

        result = self.executor.execute_tensor(r, concat=True)[0]
        expected = np.c_[np.array([1, 2, 3]), np.array([4, 5, 6])]
        np.testing.assert_array_equal(result, expected)

        r = mt.c_[mt.array([[1, 2, 3]]), 0, 0, mt.array([[4, 5, 6]])]

        result = self.executor.execute_tensor(r, concat=True)[0]
        expected = np.c_[np.array([[1, 2, 3]]), 0, 0, np.array([[4, 5, 6]])]
        np.testing.assert_array_equal(result, expected)

        r = mt.c_[:3, 1:4]
        result = self.executor.execute_tensor(r, concat=True)[0]
        expected = np.c_[:3, 1:4]
        np.testing.assert_array_equal(result, expected) 
开发者ID:mars-project,项目名称:mars,代码行数:19,代码来源:test_index_tricks.py

示例9: test_orthogonalize_dense

# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import c_ [as 别名]
def test_orthogonalize_dense(collection):
    transform.Factor(collection, 'trial_type', sep=sep)

    sampling_rate = collection.sampling_rate
    # Store pre-orth variables needed for tests
    pg_pre = collection['trial_type/parametric gain'].to_dense(sampling_rate)
    rt = collection['RT'].to_dense(sampling_rate)

    # Orthogonalize and store result
    transform.Orthogonalize(collection, variables='trial_type/parametric gain',
                            other='RT', dense=True, groupby=['run', 'subject'])
    pg_post = collection['trial_type/parametric gain']

    # Verify that the to_dense() calls result in identical indexing
    ent_cols = ['subject', 'run']
    assert pg_pre.to_df()[ent_cols].equals(rt.to_df()[ent_cols])
    assert pg_post.to_df()[ent_cols].equals(rt.to_df()[ent_cols])

    vals = np.c_[rt.values, pg_pre.values, pg_post.values]
    df = pd.DataFrame(vals, columns=['rt', 'pre', 'post'])
    groupby = rt.get_grouper(['run', 'subject'])
    pre_r = df.groupby(groupby).apply(lambda x: x.corr().iloc[0, 1])
    post_r = df.groupby(groupby).apply(lambda x: x.corr().iloc[0, 2])
    assert (pre_r > 0.2).any()
    assert (post_r < 0.0001).all() 
开发者ID:bids-standard,项目名称:pybids,代码行数:27,代码来源:test_transformations.py

示例10: compute_similarity_transform

# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import c_ [as 别名]
def compute_similarity_transform(points_static, points_to_transform):
    #http://nghiaho.com/?page_id=671
    p0 = np.copy(points_static).T
    p1 = np.copy(points_to_transform).T

    t0 = -np.mean(p0, axis=1).reshape(3,1)
    t1 = -np.mean(p1, axis=1).reshape(3,1)
    t_final = t1 -t0

    p0c = p0+t0
    p1c = p1+t1

    covariance_matrix = p0c.dot(p1c.T)
    U,S,V = np.linalg.svd(covariance_matrix)
    R = U.dot(V)
    if np.linalg.det(R) < 0:
        R[:,2] *= -1

    rms_d0 = np.sqrt(np.mean(np.linalg.norm(p0c, axis=0)**2))
    rms_d1 = np.sqrt(np.mean(np.linalg.norm(p1c, axis=0)**2))

    s = (rms_d0/rms_d1)
    P = np.c_[s*np.eye(3).dot(R), t_final]
    return P 
开发者ID:joseph-zhong,项目名称:LipReading,代码行数:26,代码来源:estimate_pose.py

示例11: compute_similarity_transform

# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import c_ [as 别名]
def compute_similarity_transform(points_static, points_to_transform):
    # http://nghiaho.com/?page_id=671
    p0 = np.copy(points_static).T
    p1 = np.copy(points_to_transform).T

    t0 = -np.mean(p0, axis=1).reshape(3, 1)
    t1 = -np.mean(p1, axis=1).reshape(3, 1)
    t_final = t1 - t0

    p0c = p0 + t0
    p1c = p1 + t1

    covariance_matrix = p0c.dot(p1c.T)
    U, S, V = np.linalg.svd(covariance_matrix)
    R = U.dot(V)
    if np.linalg.det(R) < 0:
        R[:, 2] *= -1

    rms_d0 = np.sqrt(np.mean(np.linalg.norm(p0c, axis=0) ** 2))
    rms_d1 = np.sqrt(np.mean(np.linalg.norm(p1c, axis=0) ** 2))

    s = (rms_d0 / rms_d1)
    P = np.c_[s * np.eye(3).dot(R), t_final]
    return P 
开发者ID:tensorboy,项目名称:centerpose,代码行数:26,代码来源:estimate_pose.py

示例12: exact_xp_2_xxstg_mad

# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import c_ [as 别名]
def exact_xp_2_xxstg_mad(xp, gamref):
    # to mad format
    N = xp.shape[0]
    xxstg = np.zeros((N, 6))
    pref = m_e_eV * np.sqrt(gamref ** 2 - 1)
    u = np.c_[xp[:, 3], xp[:, 4], xp[:, 5] + pref]
    gamma = np.sqrt(1 + np.sum(u * u, 1) / m_e_eV ** 2)
    beta = np.sqrt(1 - gamma ** -2)
    betaref = np.sqrt(1 - gamref ** -2)
    if np.__version__ > "1.8":
        p0 = np.linalg.norm(u, 2, 1).reshape((N, 1))
    else:
        p0 = np.sqrt(u[:, 0] ** 2 + u[:, 1] ** 2 + u[:, 2] ** 2).reshape((N, 1))
    u = u / p0
    cdt = -xp[:, 2] / (beta * u[:, 2])
    xxstg[:, 0] = xp[:, 0] + beta * u[:, 0] * cdt
    xxstg[:, 2] = xp[:, 1] + beta * u[:, 1] * cdt
    xxstg[:, 4] = cdt
    xxstg[:, 1] = xp[:, 3] / pref
    xxstg[:, 3] = xp[:, 4] / pref
    xxstg[:, 5] = (gamma / gamref - 1) / betaref
    return xxstg 
开发者ID:ocelot-collab,项目名称:ocelot,代码行数:24,代码来源:astra2ocelot.py

示例13: exact_xxstg_2_xp_mad

# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import c_ [as 别名]
def exact_xxstg_2_xp_mad(xxstg, gamref):
    # from mad format
    N = int(xxstg.size / 6)
    xp = np.zeros((N, 6))
    pref = m_e_eV * np.sqrt(gamref ** 2 - 1)
    betaref = np.sqrt(1 - gamref ** -2)
    gamma = (betaref * xxstg[5] + 1) * gamref
    beta = np.sqrt(1 - gamma ** -2)

    pz2pref = np.sqrt(((gamma * beta) / (gamref * betaref)) ** 2 - xxstg[1] ** 2 - xxstg[3] ** 2)

    u = np.c_[xxstg[1] / pz2pref, xxstg[3] / pz2pref, np.ones(N)]
    if np.__version__ > "1.8":
        norm = np.linalg.norm(u, 2, 1).reshape((N, 1))
    else:
        norm = np.sqrt(u[:, 0] ** 2 + u[:, 1] ** 2 + u[:, 2] ** 2).reshape((N, 1))
    u = u / norm
    xp[:, 0] = xxstg[0] - u[:, 0] * beta * xxstg[4]
    xp[:, 1] = xxstg[2] - u[:, 1] * beta * xxstg[4]
    xp[:, 2] = -u[:, 2] * beta * xxstg[4]
    xp[:, 3] = u[:, 0] * gamma * beta * m_e_eV
    xp[:, 4] = u[:, 1] * gamma * beta * m_e_eV
    xp[:, 5] = u[:, 2] * gamma * beta * m_e_eV - pref
    return xp 
开发者ID:ocelot-collab,项目名称:ocelot,代码行数:26,代码来源:astra2ocelot.py

示例14: exact_xp_2_xxstg_dp

# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import c_ [as 别名]
def exact_xp_2_xxstg_dp(xp, gamref):
    # dp/p0
    N = xp.shape[0]
    xxstg = np.zeros((N, 6))
    pref = m_e_eV * np.sqrt(gamref ** 2 - 1)
    u = np.c_[xp[:, 3], xp[:, 4], xp[:, 5] + pref]
    gamma = np.sqrt(1 + np.sum(u * u, 1) / m_e_eV ** 2)
    beta = np.sqrt(1 - gamma ** -2)
    if np.__version__ > "1.8":
        p0 = np.linalg.norm(u, 2, 1).reshape((N, 1))
    else:
        p0 = np.sqrt(u[:, 0] ** 2 + u[:, 1] ** 2 + u[:, 2] ** 2).reshape((N, 1))
    u = u / p0
    cdt = -xp[:, 2] / (beta * u[:, 2])
    xxstg[:, 0] = xp[:, 0] + beta * u[:, 0] * cdt
    xxstg[:, 2] = xp[:, 1] + beta * u[:, 1] * cdt
    xxstg[:, 4] = cdt
    xxstg[:, 1] = u[:, 0] / u[:, 2]
    xxstg[:, 3] = u[:, 1] / u[:, 2]
    xxstg[:, 5] = p0.reshape(N) / pref - 1
    return xxstg 
开发者ID:ocelot-collab,项目名称:ocelot,代码行数:23,代码来源:astra2ocelot.py

示例15: exact_xp_2_xxstg_de

# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import c_ [as 别名]
def exact_xp_2_xxstg_de(xp, gamref):
    # dE/E0
    N = xp.shape[0]
    xxstg = np.zeros((N, 6))
    pref = m_e_eV * np.sqrt(gamref ** 2 - 1)
    u = np.c_[xp[:, 3], xp[:, 4], xp[:, 5] + pref]
    gamma = np.sqrt(1 + np.sum(u * u, 1) / m_e_eV ** 2)
    beta = np.sqrt(1 - gamma ** -2)
    if np.__version__ > "1.8":
        p0 = np.linalg.norm(u, 2, 1).reshape((N, 1))
    else:
        p0 = np.sqrt(u[:, 0] ** 2 + u[:, 1] ** 2 + u[:, 2] ** 2).reshape((N, 1))
    u = u / p0
    cdt = -xp[:, 2] / (beta * u[:, 2])
    xxstg[:, 0] = xp[:, 0] + beta * u[:, 0] * cdt
    xxstg[:, 2] = xp[:, 1] + beta * u[:, 1] * cdt
    xxstg[:, 4] = cdt
    xxstg[:, 1] = u[:, 0] / u[:, 2]
    xxstg[:, 3] = u[:, 1] / u[:, 2]
    xxstg[:, 5] = gamma / gamref - 1
    return xxstg 
开发者ID:ocelot-collab,项目名称:ocelot,代码行数:23,代码来源:astra2ocelot.py


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