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


Python numpy.tril_indices_from函数代码示例

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


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

示例1: test_pairplot_reg

    def test_pairplot_reg(self):

        vars = ["x", "y", "z"]
        g = ag.pairplot(self.df, diag_kind="hist", kind="reg")

        for ax in g.diag_axes:
            nt.assert_equal(len(ax.patches), 10)

        for i, j in zip(*np.triu_indices_from(g.axes, 1)):
            ax = g.axes[i, j]
            x_in = self.df[vars[j]]
            y_in = self.df[vars[i]]
            x_out, y_out = ax.collections[0].get_offsets().T
            npt.assert_array_equal(x_in, x_out)
            npt.assert_array_equal(y_in, y_out)

            nt.assert_equal(len(ax.lines), 1)
            nt.assert_equal(len(ax.collections), 2)

        for i, j in zip(*np.tril_indices_from(g.axes, -1)):
            ax = g.axes[i, j]
            x_in = self.df[vars[j]]
            y_in = self.df[vars[i]]
            x_out, y_out = ax.collections[0].get_offsets().T
            npt.assert_array_equal(x_in, x_out)
            npt.assert_array_equal(y_in, y_out)

            nt.assert_equal(len(ax.lines), 1)
            nt.assert_equal(len(ax.collections), 2)

        for i, j in zip(*np.diag_indices_from(g.axes)):
            ax = g.axes[i, j]
            nt.assert_equal(len(ax.collections), 0)
开发者ID:mwaskom,项目名称:seaborn,代码行数:33,代码来源:test_axisgrid.py

示例2: test_pairplot

    def test_pairplot(self):

        vars = ["x", "y", "z"]
        g = ag.pairplot(self.df)

        for ax in g.diag_axes:
            assert len(ax.patches) > 1

        for i, j in zip(*np.triu_indices_from(g.axes, 1)):
            ax = g.axes[i, j]
            x_in = self.df[vars[j]]
            y_in = self.df[vars[i]]
            x_out, y_out = ax.collections[0].get_offsets().T
            npt.assert_array_equal(x_in, x_out)
            npt.assert_array_equal(y_in, y_out)

        for i, j in zip(*np.tril_indices_from(g.axes, -1)):
            ax = g.axes[i, j]
            x_in = self.df[vars[j]]
            y_in = self.df[vars[i]]
            x_out, y_out = ax.collections[0].get_offsets().T
            npt.assert_array_equal(x_in, x_out)
            npt.assert_array_equal(y_in, y_out)

        for i, j in zip(*np.diag_indices_from(g.axes)):
            ax = g.axes[i, j]
            nt.assert_equal(len(ax.collections), 0)

        g = ag.pairplot(self.df, hue="a")
        n = len(self.df.a.unique())

        for ax in g.diag_axes:
            assert len(ax.lines) == n
            assert len(ax.collections) == n
开发者ID:mwaskom,项目名称:seaborn,代码行数:34,代码来源:test_axisgrid.py

示例3: transform_covars_grad

 def transform_covars_grad(self, internal_grad):
     grad = np.empty((self.num_latent, self.get_covar_size()), dtype=np.float32)
     for j in range(self.num_latent):
         tmp = self._theano_transform_covars_grad(internal_grad[0, j], self.covars_cholesky[j])
         tmp[np.diag_indices_from(tmp)] *= self.covars_cholesky[j][np.diag_indices_from(tmp)]
         grad[j] = tmp[np.tril_indices_from(self.covars_cholesky[j])]
     return grad.flatten()
开发者ID:Karl-Krauth,项目名称:Sparse-GP,代码行数:7,代码来源:full_gaussian_mixture.py

示例4: test_map_diag_and_offdiag

    def test_map_diag_and_offdiag(self):

        vars = ["x", "y", "z"]
        g = ag.PairGrid(self.df)
        g.map_offdiag(plt.scatter)
        g.map_diag(plt.hist)

        for ax in g.diag_axes:
            nt.assert_equal(len(ax.patches), 10)

        for i, j in zip(*np.triu_indices_from(g.axes, 1)):
            ax = g.axes[i, j]
            x_in = self.df[vars[j]]
            y_in = self.df[vars[i]]
            x_out, y_out = ax.collections[0].get_offsets().T
            npt.assert_array_equal(x_in, x_out)
            npt.assert_array_equal(y_in, y_out)

        for i, j in zip(*np.tril_indices_from(g.axes, -1)):
            ax = g.axes[i, j]
            x_in = self.df[vars[j]]
            y_in = self.df[vars[i]]
            x_out, y_out = ax.collections[0].get_offsets().T
            npt.assert_array_equal(x_in, x_out)
            npt.assert_array_equal(y_in, y_out)

        for i, j in zip(*np.diag_indices_from(g.axes)):
            ax = g.axes[i, j]
            nt.assert_equal(len(ax.collections), 0)
开发者ID:GeorgeMcIntire,项目名称:seaborn,代码行数:29,代码来源:test_axisgrid.py

示例5: _get_raw_covars

 def _get_raw_covars(self):
     flattened_covars = np.empty([self.num_latent, self.get_covar_size()], dtype=np.float32)
     for i in xrange(self.num_latent):
         raw_covars = self.covars_cholesky[i].copy()
         raw_covars[np.diag_indices_from(raw_covars)] = np.log(raw_covars[np.diag_indices_from(raw_covars)])
         flattened_covars[i] = raw_covars[np.tril_indices_from(raw_covars)]
     return flattened_covars.flatten()
开发者ID:Karl-Krauth,项目名称:Sparse-GP,代码行数:7,代码来源:full_gaussian_mixture.py

示例6: map_lower

    def map_lower(self, func, **kwargs):
        """Plot with a bivariate function on the lower diagonal subplots.

        Parameters
        ----------
        func : callable plotting function
            Must take x, y arrays as positional arguments and draw onto the
            "currently active" matplotlib Axes.

        """
        kw_color = kwargs.pop("color", None)
        for i, j in zip(*np.tril_indices_from(self.axes, -1)):
            hue_grouped = self.data.groupby(self.hue_vals)
            for k, (label_k, data_k) in enumerate(hue_grouped):

                ax = self.axes[i, j]
                plt.sca(ax)

                x_var = self.x_vars[j]
                y_var = self.y_vars[i]

                color = self.palette[k] if kw_color is None else kw_color
                func(data_k[x_var], data_k[y_var], label=label_k,
                     color=color, **kwargs)

            self._clean_axis(ax)
            self._update_legend_data(ax)

        if kw_color is not None:
            kwargs["color"] = kw_color
        self._add_axis_labels()
开发者ID:andreas-h,项目名称:seaborn,代码行数:31,代码来源:axisgrid.py

示例7: test_pairplot

    def test_pairplot(self):

        vars = ["x", "y", "z"]
        g = pairplot(self.df)

        for ax in g.diag_axes:
            nt.assert_equal(len(ax.patches), 10)

        for i, j in zip(*np.triu_indices_from(g.axes, 1)):
            ax = g.axes[i, j]
            x_in = self.df[vars[j]]
            y_in = self.df[vars[i]]
            x_out, y_out = ax.collections[0].get_offsets().T
            npt.assert_array_equal(x_in, x_out)
            npt.assert_array_equal(y_in, y_out)

        for i, j in zip(*np.tril_indices_from(g.axes, -1)):
            ax = g.axes[i, j]
            x_in = self.df[vars[j]]
            y_in = self.df[vars[i]]
            x_out, y_out = ax.collections[0].get_offsets().T
            npt.assert_array_equal(x_in, x_out)
            npt.assert_array_equal(y_in, y_out)

        for i, j in zip(*np.diag_indices_from(g.axes)):
            ax = g.axes[i, j]
            nt.assert_equal(len(ax.collections), 0)

        plt.close("all")
开发者ID:c-wilson,项目名称:seaborn,代码行数:29,代码来源:test_axisgrid.py

示例8: net_sample_multinomial

 def net_sample_multinomial(A, minEdges, edgesPerSample=1, *args, **kwargs):
     """ NETWORK SAMPLING ALGORITHM:
     sample networks ties from multinomial distribution
     defined as 1/AAT[i,j] normalized by  sum(AAT[i>j])
     problem: doesn't sufficiently cluster the resulting network
              doesn't return exact number of ties, only at least as many as 
              specified minEdges
     """
     draws = int(np.ceil(minEdges*1.2))
     # pairwise distances between observations
     dist = pdist(A)   # what matrix to use:  pdist(A) or just tril(AAT) directly?
     invdist = dist
     invdist[invdist != 0] = 1/invdist[invdist!=0]  # prevent division by 0
     thetavec = invdist / np.sum(invdist)
     theta = squareform(thetavec)
     
     # multinomial sample
     n = np.shape(theta)[0]
     Z = np.zeros((n,n))
     # samp = sampleLinks(q=thetavec, edgesToDraw=1, draws=draws)
     y = np.random.multinomial(edgesPerSample, thetavec, draws)
     samp = np.asarray([np.mean([y[draw][item] for draw in np.arange(draws)]) for item in np.arange(len(thetavec))])
     samp = np.ceil(samp)
     
     # repeat until reaching enough network ties
     while np.sum(samp) < minEdges:
         draws = int(np.ceil(draws * 1.1))   #increase number of draws and try again
         #samp = sampleLinks(q=thetavec,edgesToDraw=1,draws=draws)
         y = np.random.multinomial(edgesPerSample, thetavec, draws)
         samp = np.asarray([np.mean([y[draw][item] for draw in np.arange(draws)]) for item in np.arange(len(thetavec))])
         samp = np.ceil(samp)
     
     Z[np.tril_indices_from(Z, k =-1)] = samp
     
     return (theta, Z)
开发者ID:sdownin,项目名称:netCreate,代码行数:35,代码来源:netcreate_previous_version.py

示例9: set_params

 def set_params(self, values):
     self.lengthscales = values[:-1]
     self.variance = values[-1]
     L = np.zeros((self.num_dim, self.num_dim))
     L[np.tril_indices_from(L)] = self.lengthscales
     self.L_inv = inv(L)
     self.projection = np.dot(self.L_inv.T, self.L_inv)
开发者ID:jgosmann,项目名称:plume,代码行数:7,代码来源:prediction.py

示例10: __init__

 def __init__(self, lengthscale_mat, variance=1.0):
     lengthscale_mat = np.asarray(lengthscale_mat)
     assert lengthscale_mat.shape[0] == lengthscale_mat.shape[1]
     self.num_dim = lengthscale_mat.shape[0]
     self.params = np.concatenate((
         lengthscale_mat[np.tril_indices_from(lengthscale_mat)],
         np.array([variance])))
开发者ID:jgosmann,项目名称:plume,代码行数:7,代码来源:prediction.py

示例11: shepard

	def shepard(self, xax=1, yax=2):
		coords = self.U[:,[xax-1, yax-1]]
		reducedD = np.zeros((coords.shape[0], coords.shape[0]))
		for i in xrange(coords.shape[0]):
			for j in xrange(coords.shape[0]):
				d = coords[i,:] - coords[j,:]
				reducedD[i, j] = np.sqrt( d.dot(d) )
		reducedD = reducedD[np.tril_indices_from(reducedD, k=-1)]
		originalD = self.y2[np.tril_indices_from(self.y2, k=-1)]
		xmin = np.min(reducedD)
		xmax = np.max(reducedD)
		f, ax = py.subplots()
		ax.plot(reducedD, originalD, 'ko')
		ax.plot([xmin, xmax], [xmin, xmax], 'r--')
		ax.set_xlabel('Distances in Reduced Space')
		ax.set_ylabel('Distances in Original Matrix')
		py.show()
开发者ID:grovduck,项目名称:ecopy,代码行数:17,代码来源:pcoa.py

示例12: set_covars

 def set_covars(self, raw_covars):
     raw_covars = raw_covars.reshape([self.num_latent, self.get_covar_size()])
     for j in xrange(self.num_latent):
         cholesky = np.zeros([self.num_dim, self.num_dim], dtype=np.float32)
         cholesky[np.tril_indices_from(cholesky)] = raw_covars[j]
         cholesky[np.diag_indices_from(cholesky)] = np.exp(cholesky[np.diag_indices_from(cholesky)])
         self.covars_cholesky[j] = cholesky
         self.covars[j] = mdot(self.covars_cholesky[j], self.covars_cholesky[j].T)
开发者ID:Karl-Krauth,项目名称:Sparse-GP,代码行数:8,代码来源:full_gaussian_mixture.py

示例13: find_smallest_index

def find_smallest_index(matrice):
    """Return smallest number i,j index in a matrice
    A Tuple (i,j) is returned.
    Warning, the diagonal should have the largest number so it will never be choose
    """

    index = np.tril_indices_from(matrice, -1)
    return np.vstack(index)[:, matrice[index].argmin()]
开发者ID:UdeM-LBIT,项目名称:profileNJ,代码行数:8,代码来源:ClusterUtils.py

示例14: _band_infinite

    def _band_infinite():
        '''Suppress the diagonal+- of a distance matrix'''
        band       = np.empty( (t, t) )
        band[:]    = np.inf
        band[np.triu_indices_from(band, width)] = 0
        band[np.tril_indices_from(band, -width)] = 0

        return band
开发者ID:BWalburn,项目名称:librosa,代码行数:8,代码来源:segment.py

示例15: from_vector

def from_vector(x):
    # Solution to the equation len(x) = n * (n + 1) / 2
    n = int((math.sqrt(len(x) * 8 + 1) - 1) / 2)
    result = np.zeros((n, n))
    result[np.tril_indices_from(result, -1)] = x[n:]
    result += result.transpose()
    result[np.diag_indices_from(result)] = x[:n]
    return result
开发者ID:filmor,项目名称:python-ma,代码行数:8,代码来源:noise_filter.py


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