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


Python numpy.copysign方法代碼示例

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


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

示例1: test_cross_div

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import copysign [as 別名]
def test_cross_div(dtypea, dtypeb, dtypec):
    if dtypea == np.int8 and dtypeb == np.int8:
        pytest.skip("Different behaviour in c++ and python for int8 / int8".format(dtypea, dtypeb))
    def fkt(a, b, c):
        c[:] = a / b
    hfkt = hope.jit(fkt)
    (ao, ah), (bo, bh), (co, ch) = random(dtypea, [10]), random(dtypeb, [10]), random(dtypec, [10])
    ao, ah, bo, bh = ao.astype(np.float64), ah.astype(np.float64), bo.astype(np.float64), bh.astype(np.float64)
    ao, ah = np.copysign(np.power(np.abs(ao), 1. / 4.), ao).astype(dtypea), np.copysign(np.power(np.abs(ah), 1. / 4.), ah).astype(dtypea)
    bo, bh = np.copysign(np.power(np.abs(bo), 1. / 4.), bo).astype(dtypeb), np.copysign(np.power(np.abs(bh), 1. / 4.), bh).astype(dtypeb)
    if np.count_nonzero(bo == 0) > 0: bo[bo == 0] += 1
    if np.count_nonzero(bh == 0) > 0: bh[bh == 0] += 1
    fkt(ao, bo, co),  hfkt(ah, bh, ch)
    assert check(co, ch)
    fkt(ao, bo, co),  hfkt(ah, bh, ch)
    assert check(co, ch) 
開發者ID:jakeret,項目名稱:hope,代碼行數:18,代碼來源:test_op_div.py

示例2: __init__

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import copysign [as 別名]
def __init__(
        self,
        asset,
        quantity,
        dt,
        price,
        order_id,
        commission=0.0
    ):
        self.asset = asset
        self.quantity = quantity
        self.direction = np.copysign(1, self.quantity)
        self.dt = dt
        self.price = price
        self.order_id = order_id
        self.commission = commission 
開發者ID:mhallsmoore,項目名稱:qstrader,代碼行數:18,代碼來源:transaction.py

示例3: to_geodetic

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import copysign [as 別名]
def to_geodetic(z_coord, hypot_xy):
        """ Get geodetic coordinates calculated by the Ferrarri's solution. """
        ee4 = WGS84_EPS2**2
        pa2 = (hypot_xy / WGS84_A)**2
        zt = (1.0 - WGS84_EPS2) * (z_coord / WGS84_A)**2
        rh = (pa2 + zt - ee4)/6.0
        ss = (0.25*ee4) * zt * pa2
        rh3 = rh**3
        tmp = rh3 + ss + sqrt(ss*(ss+2.0*rh3))
        tt = copysign(fabs(tmp)**(1.0/3.0), tmp)
        uu = rh + tt + rh**2 / tt
        vv = sqrt(uu**2 + ee4*zt)
        ww = (0.5*WGS84_EPS2) * (uu + vv - zt)/vv
        kp = 1.0 + WGS84_EPS2*(sqrt(uu + vv + ww**2) + ww)/(uu + vv)
        zkp = kp * z_coord
        return (
            RAD2DEG*arctan2(zkp, hypot_xy),
            hypot(hypot_xy, zkp)*(1.0/kp - 1.0 + WGS84_EPS2)/WGS84_EPS2
        ) 
開發者ID:igp-gravity,項目名稱:geoist,代碼行數:21,代碼來源:pymm_convert.py

示例4: custom_line

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import copysign [as 別名]
def custom_line(
        self, name: str, data: np.ndarray, offset: bool, invert: bool = True
    ):
        """
        :param offset:
        - True, for untriggered wave data:
            - line will be shifted and triggered (by offset_viewport()).
        - False, for triggered data and buffers:
            - line is immune to offset_viewport().

        :param invert:
        - True, for wave (data and buffers):
            - If wave data is inverted (edge_direction = -1),
              data will be plotted inverted.
        - False, for buffers and autocorrelated wave data:
            - Data is plotted as-is.
        """
        if self._renderer is None:
            return
        data = data / abs_max(data, 0.01) / 2
        if invert:
            data *= np.copysign(1, self._wave.amplification)
        self._renderer.update_custom_line(
            name, self._wave_idx, self._stride, data, offset=offset
        ) 
開發者ID:corrscope,項目名稱:corrscope,代碼行數:27,代碼來源:triggers.py

示例5: dms_to_degrees

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import copysign [as 別名]
def dms_to_degrees(d, m, s=None):
    """
    Convert degrees, arcminute, arcsecond to a float degrees value.
    """

    _check_minute_range(m)
    _check_second_range(s)

    # determine sign
    sign = np.copysign(1.0, d)

    try:
        d = np.floor(np.abs(d))
        if s is None:
            m = np.abs(m)
            s = 0
        else:
            m = np.floor(np.abs(m))
            s = np.abs(s)
    except ValueError:
        raise ValueError(format_exception(
            "{func}: dms values ({1[0]},{2[1]},{3[2]}) could not be "
            "converted to numbers.", d, m, s))

    return sign * (d + m / 60. + s / 3600.) 
開發者ID:holzschu,項目名稱:Carnets,代碼行數:27,代碼來源:angle_utilities.py

示例6: hms_to_hours

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import copysign [as 別名]
def hms_to_hours(h, m, s=None):
    """
    Convert hour, minute, second to a float hour value.
    """

    check_hms_ranges(h, m, s)

    # determine sign
    sign = np.copysign(1.0, h)

    try:
        h = np.floor(np.abs(h))
        if s is None:
            m = np.abs(m)
            s = 0
        else:
            m = np.floor(np.abs(m))
            s = np.abs(s)
    except ValueError:
        raise ValueError(format_exception(
            "{func}: HMS values ({1[0]},{2[1]},{3[2]}) could not be "
            "converted to numbers.", h, m, s))

    return sign * (h + m / 60. + s / 3600.) 
開發者ID:holzschu,項目名稱:Carnets,代碼行數:26,代碼來源:angle_utilities.py

示例7: idl_round

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import copysign [as 別名]
def idl_round(x):
    """
    Round to the *nearest* integer, half-away-from-zero.

    Parameters
    ----------
    x : array-like
        Number or array to be rounded

    Returns
    -------
    r_rounded : array-like
        note that the returned values are floats

    Notes
    -----
    IDL ``ROUND`` rounds to the *nearest* integer (commercial rounding),
    unlike numpy's round/rint, which round to the nearest *even*
    value (half-to-even, financial rounding) as defined in IEEE-754
    standard.

    """
    return np.trunc(x + np.copysign(0.5, x)) 
開發者ID:vortex-exoplanet,項目名稱:VIP,代碼行數:25,代碼來源:utils.py

示例8: __call__

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import copysign [as 別名]
def __call__(self, array):
        if self.dtype is not None:
            assert array.dtype == self.dtype
        xp = cuda.get_array_module(array)
        if not array.shape:  # 0-dim case
            array[...] = self.scale * (2 * numpy.random.randint(2) - 1)
        elif not array.size:
            raise ValueError('Array to be initialized must be non-empty.')
        else:
            # numpy.prod returns float value when the argument is empty.
            out_dim = len(array)
            in_dim = size_of_shape(array.shape[1:])
            if (in_dim > out_dim and self._checks[0]) or (
                    in_dim < out_dim and self._checks[1]):
                raise ValueError(
                    'Cannot make orthogonal {}.'
                    'shape = {}, interpreted as '
                    '{}-dim input and {}-dim output.'.format(
                        self.mode, array.shape, in_dim, out_dim))
            transpose = in_dim > out_dim
            a = numpy.random.normal(size=(out_dim, in_dim))
            if transpose:
                a = a.T
            # cupy.linalg.qr requires cusolver in CUDA 8+
            q, r = numpy.linalg.qr(a)
            q *= numpy.copysign(self.scale, numpy.diag(r))
            if transpose:
                q = q.T
            array[...] = xp.asarray(q.reshape(array.shape)) 
開發者ID:chainer,項目名稱:chainerrl,代碼行數:31,代碼來源:orthogonal.py

示例9: test_copysign

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import copysign [as 別名]
def test_copysign():
    assert_(np.copysign(1, -1) == -1)
    with np.errstate(divide="ignore"):
        assert_(1 / np.copysign(0, -1) < 0)
        assert_(1 / np.copysign(0, 1) > 0)
    assert_(np.signbit(np.copysign(np.nan, -1)))
    assert_(not np.signbit(np.copysign(np.nan, 1))) 
開發者ID:Frank-qlu,項目名稱:recruit,代碼行數:9,代碼來源:test_umath.py

示例10: f32_copysign

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import copysign [as 別名]
def f32_copysign(config: Configuration, i: binary.Instruction):
        b = config.stack.pop().f32()
        a = config.stack.pop().f32()
        r = Value.from_f32(numpy.copysign(a, b))
        config.stack.append(r) 
開發者ID:mohanson,項目名稱:pywasm,代碼行數:7,代碼來源:execution.py

示例11: f64_copysign

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import copysign [as 別名]
def f64_copysign(config: Configuration, i: binary.Instruction):
        b = config.stack.pop().f64()
        a = config.stack.pop().f64()
        r = Value.from_f64(numpy.copysign(a, b))
        config.stack.append(r) 
開發者ID:mohanson,項目名稱:pywasm,代碼行數:7,代碼來源:execution.py

示例12: __call__

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import copysign [as 別名]
def __call__(self, array):
        if self.dtype is not None:
            assert array.dtype == self.dtype,\
                '{} != {}'.format(array.dtype, self.dtype)
        if not array.shape:  # 0-dim case
            if self.rng is None:
                a = numpy.random.randint(2)
            else:
                a = self.rng.randint(2)
            a = int(a)
            array[...] = self.scale * (2 * a - 1)
        elif not array.size:
            raise ValueError('Array to be initialized must be non-empty.')
        else:
            # numpy.prod returns float value when the argument is empty.
            out_dim = len(array)
            in_dim = utils.size_of_shape(array.shape[1:])
            if (in_dim > out_dim and self._checks[0]) or (
                    in_dim < out_dim and self._checks[1]):
                raise ValueError(
                    'Cannot make orthogonal {}. '
                    'shape = {}, interpreted as '
                    '{}-dim input and {}-dim output.'.format(
                        self.mode, array.shape, in_dim, out_dim))
            transpose = in_dim > out_dim
            if self.rng is None:
                a = numpy.random.normal(size=(out_dim, in_dim))
            else:
                a_tmp = self.rng.normal(size=(out_dim, in_dim))
                a = numpy.empty(a_tmp.shape, dtype=a_tmp.dtype)
                backend.copyto(a, a_tmp)
            if transpose:
                a = a.T
            # cupy.linalg.qr requires cusolver in CUDA 8+
            q, r = numpy.linalg.qr(a)
            q *= numpy.copysign(self.scale, numpy.diag(r))
            if transpose:
                q = q.T
            backend.copyto(array, q.reshape(array.shape).astype(
                array.dtype, copy=False)) 
開發者ID:chainer,項目名稱:chainer,代碼行數:42,代碼來源:orthogonal.py

示例13: _boundary_inputs

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import copysign [as 別名]
def _boundary_inputs(boundary, rtol, atol):
    left = boundary * (1 - numpy.copysign(rtol, boundary)) - atol
    right = boundary * (1 + numpy.copysign(rtol, boundary)) + atol
    return [left, boundary, right] 
開發者ID:cupy,項目名稱:cupy,代碼行數:6,代碼來源:test_erf.py

示例14: opposite_side_port_out

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import copysign [as 別名]
def opposite_side_port_out(self):
        return self.port.parallel_offset(np.copysign(2 * self.radius + self.vertical_race_length, self.opposite_gap)
                                         + self._offset + self._offset_opposite) 
開發者ID:HelgeGehring,項目名稱:gdshelpers,代碼行數:5,代碼來源:resonator.py

示例15: opposite_side_port_in

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import copysign [as 別名]
def opposite_side_port_in(self):
        return self._origin_port.parallel_offset(
            np.copysign(2 * self.radius + self.vertical_race_length, self.opposite_gap)
            + self._offset + self._offset_opposite).inverted_direction

    # Conventional naming of ports 
開發者ID:HelgeGehring,項目名稱:gdshelpers,代碼行數:8,代碼來源:resonator.py


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