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


Python numpy.cbrt方法代码示例

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


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

示例1: _no_extrapolation_hessian

# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import cbrt [as 别名]
def _no_extrapolation_hessian(internal_func, params_value, method):
    finite_diff = getattr(aux, method)
    hess = np.empty((len(params_value), len(params_value)))
    for i, val_1 in enumerate(params_value):
        h_1 = (1.0 + abs(val_1)) * np.cbrt(np.finfo(float).eps)
        for j, val_2 in enumerate(params_value):
            h_2 = (1.0 + abs(val_2)) * np.cbrt(np.finfo(float).eps)
            params_r = params_value.copy()
            params_r[j] += h_2
            # Calculate the first derivative w.r.t. var_1 at (params + h_2) with
            # the central method. This is not the right f_x0, but the real one
            # isn't needed for the central method.
            f_plus = finite_diff(internal_func, None, params_r, i, h_1)
            params_l = params_value.copy()
            params_l[j] -= h_2
            # Calculate the first derivative w.r.t. var_1 at (params - h_2) with
            # the central method. This is not the right f_x0, but the real one
            # isn't needed for the central method.
            f_minus = finite_diff(internal_func, None, params_l, i, h_1)
            f_diff = (f_plus - f_minus) / (2.0 * h_1 * h_2)
            hess[i, j] = f_diff
            hess[i, j] = f_diff
    return hess 
开发者ID:OpenSourceEconomics,项目名称:estimagic,代码行数:25,代码来源:differentiation.py

示例2: from_xyz100

# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import cbrt [as 别名]
def from_xyz100(self, xyz):
        def f(t):
            delta = 6.0 / 29.0
            out = numpy.array(t, dtype=float)
            is_greater = out > delta ** 3
            out[is_greater] = 116 * numpy.cbrt(out[is_greater]) - 16
            out[~is_greater] = out[~is_greater] / (delta / 2) ** 3
            return out

        L = f(xyz[1] / self.whitepoint[1])

        x, y, z = xyz
        p = x + 15 * y + 3 * z
        u = 4 * x / p
        v = 9 * y / p

        wx, wy, wz = self.whitepoint
        q = wx + 15 * wy + 3 * wz
        un = 4 * wx / q
        vn = 9 * wy / q
        return numpy.array([L, 13 * L * (u - un), 13 * L * (v - vn)]) 
开发者ID:nschloe,项目名称:colorio,代码行数:23,代码来源:_cieluv.py

示例3: symmetrized_stress

# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import cbrt [as 别名]
def symmetrized_stress(self, stress):
        #Make the matrix lower-diagonal
        for (i,j) in [(1,0),(2,1),(2,2)]:
            stress[i][j] = stress[i][j] + stress[j][i]
            stress[j][i] = 0
        #Normalize the matrix
        snm = self.struc.lattice.stress_normalization_matrix
        m2 = np.multiply(stress, snm)
        #Normalize the on-diagonal elements
        indices = self.struc.lattice.stress_indices
        if len(indices) == 2:
            total = 0
            for index in indices:
                total += stress[index]        
            value = total**0.5
            for index in inices:
                m2[index] = value
        elif len(indices) == 3:
            total = 0
            for index in indices:
                total += stress[index]        
            value = np.cbrt(total)
            for index in inices:
                m2[index] = value
        return m2 
开发者ID:qzhu2017,项目名称:PyXtal,代码行数:27,代码来源:structure.py

示例4: symmetrized_stress

# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import cbrt [as 别名]
def symmetrized_stress(self, stress):
        #Make the matrix lower-diagonal
        for (i,j) in [(1,0),(2,1),(2,2)]:
            stress[i][j] = stress[i][j] + stress[j][i]
            stress[j][i] = 0
        #Normalize the matrix
        snm = self.struc.lattice.stress_normalization_matrix
        m2 = np.multiply(stress, snm)
        #Normalize the on-diagonal elements
        indices = self.struc.lattice.stress_indices
        if len(indices) == 2:
            total = 0
            for index in indices:
                total += stress[index]        
            value = np.sqrt(total)
            for index in inices:
                m2[index] = value
        elif len(indices) == 3:
            total = 0
            for index in indices:
                total += stress[index]        
            value = np.cbrt(total)
            for index in inices:
                m2[index] = value
        return m2 
开发者ID:qzhu2017,项目名称:PyXtal,代码行数:27,代码来源:LJ.py

示例5: random_shear_matrix

# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import cbrt [as 别名]
def random_shear_matrix(width=1.0, unitary=False):
    """
    Generate a random symmetric shear matrix with Gaussian elements. If unitary
    is True, normalize to determinant 1

    Args:
        width: the width of the normal distribution to use when choosing values.
            Passed to np.random.normal
        unitary: whether or not to normalize the matrix to determinant 1
    
    Returns:
        a 3x3 numpy array of floats
    """
    mat = np.zeros([3,3])
    determinant = 0
    while determinant == 0:
        a, b, c = np.random.normal(scale=width), np.random.normal(scale=width), np.random.normal(scale=width)
        mat = np.array([[1,a,b],[a,1,c],[b,c,1]])
        determinant = np.linalg.det(mat)
    if unitary:
        new = mat / np.cbrt(np.linalg.det(mat))
        return new
    else: return mat 
开发者ID:qzhu2017,项目名称:PyXtal,代码行数:25,代码来源:operations.py

示例6: _subsample_array

# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import cbrt [as 别名]
def _subsample_array(self, array):
        original_shape = array.shape
        spacing = self.spacing
        extent = tuple((o_s - 1) * s for o_s, s in zip(original_shape, spacing))
        dim_ratio = np.cbrt((array.nbytes / 1e6) / self.max_data_size)
        max_shape = tuple(int(o_s / dim_ratio) for o_s in original_shape)
        dowsnscale_factor = [max(o_s, m_s) / m_s for m_s, o_s in zip(max_shape, original_shape)]

        if any([d_f > 1 for d_f in dowsnscale_factor]):
            try:
                import scipy.ndimage as nd
                sub_array = nd.interpolation.zoom(array, zoom=[1 / d_f for d_f in dowsnscale_factor], order=0)
            except ImportError:
                sub_array = array[::int(np.ceil(dowsnscale_factor[0])),
                                  ::int(np.ceil(dowsnscale_factor[1])),
                                  ::int(np.ceil(dowsnscale_factor[2]))]
            self._sub_spacing = tuple(e / (s - 1) for e, s in zip(extent, sub_array.shape))
        else:
            sub_array = array
            self._sub_spacing = self.spacing
        return sub_array 
开发者ID:holoviz,项目名称:panel,代码行数:23,代码来源:vtk.py

示例7: average_velocity

# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import cbrt [as 别名]
def average_velocity(self):
        """
        This property calculates and returns the cube root of the
        mean cubed velocity in the turbine's rotor swept area (m/s).

        Returns:
            float: The average velocity across a rotor.

        Examples:
            To get the average velocity for a turbine:

            >>> avg_vel = floris.farm.turbines[0].average_velocity()
        """
        # remove all invalid numbers from interpolation
        data = self.velocities[np.where(~np.isnan(self.velocities))]
        avg_vel = np.cbrt(np.mean(data ** 3))
        if np.isnan(avg_vel):
            avg_vel = 0
        elif np.isinf(avg_vel):
            avg_vel = 0

        return avg_vel 
开发者ID:NREL,项目名称:floris,代码行数:24,代码来源:turbine.py

示例8: _split_epsilon

# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import cbrt [as 别名]
def _split_epsilon(self, dims, total_iters, rho=0.225):
        """Split epsilon between sum perturbation and count perturbation, as proposed by Su et al.

        Parameters
        ----------
        dims : int
            Number of dimensions to split `epsilon` across.

        total_iters : int
            Total number of iterations to split `epsilon` across.

        rho : float, default: 0.225
            Coordinate normalisation factor.

        Returns
        -------
        epsilon_0 : float
            The epsilon value for satisfying differential privacy on the count of a cluster.

        epsilon_i : float
            The epsilon value for satisfying differential privacy on each dimension of the center of a cluster.

        """
        epsilon_i = 1
        epsilon_0 = np.cbrt(4 * dims * rho ** 2)

        normaliser = self.epsilon / total_iters / (epsilon_i * dims + epsilon_0)

        return epsilon_i * normaliser, epsilon_0 * normaliser 
开发者ID:IBM,项目名称:differential-privacy-library,代码行数:31,代码来源:k_means.py

示例9: _calc_iters

# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import cbrt [as 别名]
def _calc_iters(self, n_dims, n_samples, rho=0.225):
        """Calculate the number of iterations to allow for the KMeans algorithm."""

        epsilon_m = np.sqrt(500 * (self.n_clusters ** 3) / (n_samples ** 2) *
                            (n_dims + np.cbrt(4 * n_dims * (rho ** 2))) ** 3)

        iters = max(min(self.epsilon / epsilon_m, 7), 2)

        return int(iters) 
开发者ID:IBM,项目名称:differential-privacy-library,代码行数:11,代码来源:k_means.py

示例10: test_cbrt_scalar

# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import cbrt [as 别名]
def test_cbrt_scalar(self):
        assert_almost_equal((np.cbrt(np.float32(-2.5)**3)), -2.5) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:4,代码来源:test_umath.py

示例11: test_cbrt

# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import cbrt [as 别名]
def test_cbrt(self):
        x = np.array([1., 2., -3., np.inf, -np.inf])
        assert_almost_equal(np.cbrt(x**3), x)

        assert_(np.isnan(np.cbrt(np.nan)))
        assert_equal(np.cbrt(np.inf), np.inf)
        assert_equal(np.cbrt(-np.inf), -np.inf) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:9,代码来源:test_umath.py

示例12: cbrt

# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import cbrt [as 别名]
def cbrt(self):
        return self.power(1/3)

#################################################################################################### 
开发者ID:FabriceSalvaire,项目名称:PySpice,代码行数:6,代码来源:Unit.py

示例13: cbrt

# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import cbrt [as 别名]
def cbrt(x, out=None, where=None, **kwargs):
    """
    Return the cube-root of an tensor, element-wise.

    Parameters
    ----------
    x : array_like
        The values whose cube-roots are required.
    out : Tensor, None, or tuple of Tensor and None, optional
        A location into which the result is stored. If provided, it must have
        a shape that the inputs broadcast to. If not provided or `None`,
        a freshly-allocated tensor is returned. A tuple (possible only as a
        keyword argument) must have length equal to the number of outputs.
    where : array_like, optional
        Values of True indicate to calculate the ufunc at that position, values
        of False indicate to leave the value in the output alone.
    **kwargs

    Returns
    -------
    y : Tensor
        An tensor of the same shape as `x`, containing the cube
        cube-root of each element in `x`.
        If `out` was provided, `y` is a reference to it.


    Examples
    --------
    >>> import mars.tensor as mt

    >>> mt.cbrt([1,8,27]).execute()
    array([ 1.,  2.,  3.])
    """
    op = TensorCbrt(**kwargs)
    return op(x, out=out, where=where) 
开发者ID:mars-project,项目名称:mars,代码行数:37,代码来源:cbrt.py

示例14: eclipse_duration

# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import cbrt [as 别名]
def eclipse_duration(beta, period, r_p=R_E_MEAN_KM):
    """Eclipse duration, in minutes"""
    # Based on Vallado 4th ed., pp. 305
    # Circular orbital radius corresponding to given period
    r = np.cbrt(MU_E / (4 * pi ** 2) * (period * 60) ** 2)

    # We clip the argument of acos between -1 and 1
    # to return a eclipse duration of 0 when it is out of range
    return acos(
        np.clip(sqrt(1 - (r_p / r) ** 2) / cos(radians(beta)), -1, 1)
    ) * period / pi 
开发者ID:satellogic,项目名称:orbit-predictor,代码行数:13,代码来源:utils.py

示例15: CubeRootFeature

# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import cbrt [as 别名]
def CubeRootFeature(d):
	##the cube root of the difference between the two positions, the radius of protein is related to this feature
    	seqLen = len(d['sequence'])
	feature = []
	for i in range(seqLen):
		dVector = [ abs(j-i) for j in range(seqLen) ]
		feature.append(dVector)
	posFeature = np.cbrt( np.array( feature ).astype(theano.config.floatX) )
	return posFeature
	
## load native distance matrix from a file 
开发者ID:j3xugit,项目名称:RaptorX-Contact,代码行数:13,代码来源:DataProcessor.py


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