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


Python numpy.power方法代碼示例

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


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

示例1: Ixx

# 需要導入模塊: from autograd import numpy [as 別名]
# 或者: from autograd.numpy import power [as 別名]
def Ixx(self):
        # Returns the nondimensionalized Ixx moment of inertia, taken about the centroid.
        x = self.coordinates[:, 0]
        y = self.coordinates[:, 1]
        x_n = np.roll(x, -1)  # x_next, or x_i+1
        y_n = np.roll(y, -1)  # y_next, or y_i+1

        a = x * y_n - x_n * y  # a is the area of the triangle bounded by a given point, the next point, and the origin.

        A = 0.5 * np.sum(a)  # area

        x_c = 1 / (6 * A) * np.sum(a * (x + x_n))
        y_c = 1 / (6 * A) * np.sum(a * (y + y_n))
        centroid = np.array([x_c, y_c])

        Ixx = 1 / 12 * np.sum(a * (np.power(y, 2) + y * y_n + np.power(y_n, 2)))

        Iuu = Ixx - A * centroid[1] ** 2

        return Iuu 
開發者ID:peterdsharpe,項目名稱:AeroSandbox,代碼行數:22,代碼來源:geometry.py

示例2: Iyy

# 需要導入模塊: from autograd import numpy [as 別名]
# 或者: from autograd.numpy import power [as 別名]
def Iyy(self):
        # Returns the nondimensionalized Iyy moment of inertia, taken about the centroid.
        x = self.coordinates[:, 0]
        y = self.coordinates[:, 1]
        x_n = np.roll(x, -1)  # x_next, or x_i+1
        y_n = np.roll(y, -1)  # y_next, or y_i+1

        a = x * y_n - x_n * y  # a is the area of the triangle bounded by a given point, the next point, and the origin.

        A = 0.5 * np.sum(a)  # area

        x_c = 1 / (6 * A) * np.sum(a * (x + x_n))
        y_c = 1 / (6 * A) * np.sum(a * (y + y_n))
        centroid = np.array([x_c, y_c])

        Iyy = 1 / 12 * np.sum(a * (np.power(x, 2) + x * x_n + np.power(x_n, 2)))

        Ivv = Iyy - A * centroid[0] ** 2

        return Ivv 
開發者ID:peterdsharpe,項目名稱:AeroSandbox,代碼行數:22,代碼來源:geometry.py

示例3: J

# 需要導入模塊: from autograd import numpy [as 別名]
# 或者: from autograd.numpy import power [as 別名]
def J(self):
        # Returns the nondimensionalized polar moment of inertia, taken about the centroid.
        x = self.coordinates[:, 0]
        y = self.coordinates[:, 1]
        x_n = np.roll(x, -1)  # x_next, or x_i+1
        y_n = np.roll(y, -1)  # y_next, or y_i+1

        a = x * y_n - x_n * y  # a is the area of the triangle bounded by a given point, the next point, and the origin.

        A = 0.5 * np.sum(a)  # area

        x_c = 1 / (6 * A) * np.sum(a * (x + x_n))
        y_c = 1 / (6 * A) * np.sum(a * (y + y_n))
        centroid = np.array([x_c, y_c])

        Ixx = 1 / 12 * np.sum(a * (np.power(y, 2) + y * y_n + np.power(y_n, 2)))

        Iyy = 1 / 12 * np.sum(a * (np.power(x, 2) + x * x_n + np.power(x_n, 2)))

        J = Ixx + Iyy

        return J 
開發者ID:peterdsharpe,項目名稱:AeroSandbox,代碼行數:24,代碼來源:geometry.py

示例4: optimize

# 需要導入模塊: from autograd import numpy [as 別名]
# 或者: from autograd.numpy import power [as 別名]
def optimize(self, angles0, target):
        """Calculate an optimum argument of an objective function."""
        def new_objective(angles):
            a = angles - angles0
            if isinstance(self.smooth_factor, (np.ndarray, list)):
                if len(a) == len(self.smooth_factor):
                    return (self.f(angles, target) +
                            np.sum(self.smooth_factor * np.power(a, 2)))
                else:
                    raise ValueError('len(smooth_factor) != number of joints')
            else:
                return (self.f(angles, target) +
                        self.smooth_factor * np.sum(np.power(a, 2)))

        return scipy.optimize.minimize(
            new_objective,
            angles0,
            **self.optimizer_opt).x 
開發者ID:lanius,項目名稱:tinyik,代碼行數:20,代碼來源:optimizer.py

示例5: constraint_c4_cylindrical

# 需要導入模塊: from autograd import numpy [as 別名]
# 或者: from autograd.numpy import power [as 別名]
def constraint_c4_cylindrical(f, r):  # cylindrical
    l = anp.mean(f, axis=1)
    l = anp.expand_dims(l, axis=1)
    g = -anp.sum(anp.power(f - l, 2), axis=1) + anp.power(r, 2)
    return g 
開發者ID:msu-coinlab,項目名稱:pymoo,代碼行數:7,代碼來源:cdtlz.py

示例6: obj_func

# 需要導入模塊: from autograd import numpy [as 別名]
# 或者: from autograd.numpy import power [as 別名]
def obj_func(self, X_, g, alpha=1):
        f = []

        for i in range(0, self.n_obj):
            _f = (1 + g)
            _f *= anp.prod(anp.cos(anp.power(X_[:, :X_.shape[1] - i], alpha) * anp.pi / 2.0), axis=1)
            if i > 0:
                _f *= anp.sin(anp.power(X_[:, X_.shape[1] - i], alpha) * anp.pi / 2.0)

            f.append(_f)

        f = anp.column_stack(f)
        return f 
開發者ID:msu-coinlab,項目名稱:pymoo,代碼行數:15,代碼來源:dtlz.py

示例7: _evaluate

# 需要導入模塊: from autograd import numpy [as 別名]
# 或者: from autograd.numpy import power [as 別名]
def _evaluate(self, x, out, *args, **kwargs):
        X_, X_M = x[:, :self.n_obj - 1], x[:, self.n_obj - 1:]
        g = anp.sum(anp.power(X_M, 0.1), axis=1)

        theta = 1 / (2 * (1 + g[:, None])) * (1 + 2 * g[:, None] * X_)
        theta = anp.column_stack([x[:, 0], theta[:, 1:]])

        out["F"] = self.obj_func(theta, g) 
開發者ID:msu-coinlab,項目名稱:pymoo,代碼行數:10,代碼來源:dtlz.py

示例8: get_scale

# 需要導入模塊: from autograd import numpy [as 別名]
# 或者: from autograd.numpy import power [as 別名]
def get_scale(n, scale_factor):
        return anp.power(anp.full(n, scale_factor), anp.arange(n)) 
開發者ID:msu-coinlab,項目名稱:pymoo,代碼行數:4,代碼來源:dtlz.py

示例9: _evaluate

# 需要導入模塊: from autograd import numpy [as 別名]
# 或者: from autograd.numpy import power [as 別名]
def _evaluate(self, x, out, *args, **kwargs):
        a = anp.sum(0.5 * anp.arange(1, self.n_var + 1) * x, axis=1)
        out["F"] = anp.sum(anp.square(x), axis=1) + anp.square(a) + anp.power(a, 4) 
開發者ID:msu-coinlab,項目名稱:pymoo,代碼行數:5,代碼來源:zakharov.py

示例10: _evaluate

# 需要導入模塊: from autograd import numpy [as 別名]
# 或者: from autograd.numpy import power [as 別名]
def _evaluate(self, x, out, *args, **kwargs):
        z = anp.power(x, 2) - self.A * anp.cos(2 * anp.pi * x)
        out["F"] = self.A * self.n_var + anp.sum(z, axis=1) 
開發者ID:msu-coinlab,項目名稱:pymoo,代碼行數:5,代碼來源:rastrigin.py

示例11: _evaluate

# 需要導入模塊: from autograd import numpy [as 別名]
# 或者: from autograd.numpy import power [as 別名]
def _evaluate(self, x, out, *args, **kwargs):
        f1 = x[:, 0]
        g = 1 + 9.0 / (self.n_var - 1) * anp.sum(x[:, 1:], axis=1)
        f2 = g * (1 - anp.power((f1 / g), 0.5))

        out["F"] = anp.column_stack([f1, f2]) 
開發者ID:msu-coinlab,項目名稱:pymoo,代碼行數:8,代碼來源:zdt.py

示例12: _calc_pareto_front

# 需要導入模塊: from autograd import numpy [as 別名]
# 或者: from autograd.numpy import power [as 別名]
def _calc_pareto_front(self, n_pareto_points=100):
        x = anp.linspace(0, 1, n_pareto_points)
        return anp.array([x, 1 - anp.power(x, 2)]).T 
開發者ID:msu-coinlab,項目名稱:pymoo,代碼行數:5,代碼來源:zdt.py

示例13: _evaluate

# 需要導入模塊: from autograd import numpy [as 別名]
# 或者: from autograd.numpy import power [as 別名]
def _evaluate(self, x, out, *args, **kwargs):
        f1 = x[:, 0]
        g = 1 + 9.0 / (self.n_var - 1) * np.sum(x[:, 1:], axis=1)
        f2 = g * (1 - np.power((f1 / g), 0.5))

        out["F"] = np.column_stack([f1, f2])

        if "dF" in out:
            dF = np.zeros([x.shape[0], self.n_obj, self.n_var], dtype=np.float)
            dF[:, 0, 0], dF[:, 0, 1:] = 1, 0
            dF[:, 1, 0] = -0.5 * np.sqrt(g / x[:, 0])
            dF[:, 1, 1:] = ((9 / (self.n_var - 1)) * (1 - 0.5 * np.sqrt(x[:, 0] / g)))[:, None]
            out["dF"] = dF 
開發者ID:msu-coinlab,項目名稱:pymoo,代碼行數:15,代碼來源:define_custom_problem_with_gradient.py

示例14: get_downsampled_mcl

# 需要導入模塊: from autograd import numpy [as 別名]
# 或者: from autograd.numpy import power [as 別名]
def get_downsampled_mcl(self, mcl_fractions):
        # Returns the mean camber line in downsampled form

        mcl = self.mcl_coordinates
        # Find distances along mcl, assuming linear interpolation
        mcl_distances_between_points = np.sqrt(
            np.power(mcl[:-1, 0] - mcl[1:, 0], 2) +
            np.power(mcl[:-1, 1] - mcl[1:, 1], 2)
        )
        mcl_distances_cumulative = np.hstack((0, np.cumsum(mcl_distances_between_points)))
        mcl_distances_cumulative_normalized = mcl_distances_cumulative / mcl_distances_cumulative[-1]

        mcl_downsampled_x = np.interp(
            x=mcl_fractions,
            xp=mcl_distances_cumulative_normalized,
            fp=mcl[:, 0]
        )
        mcl_downsampled_y = np.interp(
            x=mcl_fractions,
            xp=mcl_distances_cumulative_normalized,
            fp=mcl[:, 1]
        )

        mcl_downsampled = np.column_stack((mcl_downsampled_x, mcl_downsampled_y))

        return mcl_downsampled 
開發者ID:peterdsharpe,項目名稱:AeroSandbox,代碼行數:28,代碼來源:geometry.py

示例15: grid

# 需要導入模塊: from autograd import numpy [as 別名]
# 或者: from autograd.numpy import power [as 別名]
def grid(num, ndim, large=False):
  """Build a uniform grid with num points along each of ndim axes."""
  if not large:
    _check_not_too_large(np.power(num, ndim) * ndim)
  x = np.linspace(0, 1, num, dtype='float64')
  w = 1 / (num - 1)
  points = np.stack(
      np.meshgrid(*[x for _ in range(ndim)], indexing='ij'), axis=-1)
  return points, w 
開發者ID:google,項目名稱:tf-quant-finance,代碼行數:11,代碼來源:methods.py


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