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


Python numpy.positive方法代码示例

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


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

示例1: positive

# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import positive [as 别名]
def positive(x, out=None, where=None, **kwargs):
    """
    Numerical positive, element-wise.

    Parameters
    ----------
    x : array_like or scalar
        Input tensor.

    Returns
    -------
    y : Tensor or scalar
        Returned array or scalar: `y = +x`.
    """
    op = TensorPositive(**kwargs)
    return op(x, out=out, where=where) 
开发者ID:mars-project,项目名称:mars,代码行数:18,代码来源:positive.py

示例2: test_datetime_unary

# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import positive [as 别名]
def test_datetime_unary(self):
        for tda, tdb, tdzero, tdone, tdmone in \
                [
                 # One-dimensional arrays
                 (np.array([3], dtype='m8[D]'),
                  np.array([-3], dtype='m8[D]'),
                  np.array([0], dtype='m8[D]'),
                  np.array([1], dtype='m8[D]'),
                  np.array([-1], dtype='m8[D]')),
                 # NumPy scalars
                 (np.timedelta64(3, '[D]'),
                  np.timedelta64(-3, '[D]'),
                  np.timedelta64(0, '[D]'),
                  np.timedelta64(1, '[D]'),
                  np.timedelta64(-1, '[D]'))]:
            # negative ufunc
            assert_equal(-tdb, tda)
            assert_equal((-tdb).dtype, tda.dtype)
            assert_equal(np.negative(tdb), tda)
            assert_equal(np.negative(tdb).dtype, tda.dtype)

            # positive ufunc
            assert_equal(np.positive(tda), tda)
            assert_equal(np.positive(tda).dtype, tda.dtype)
            assert_equal(np.positive(tdb), tdb)
            assert_equal(np.positive(tdb).dtype, tdb.dtype)

            # absolute ufunc
            assert_equal(np.absolute(tdb), tda)
            assert_equal(np.absolute(tdb).dtype, tda.dtype)

            # sign ufunc
            assert_equal(np.sign(tda), tdone)
            assert_equal(np.sign(tdb), tdmone)
            assert_equal(np.sign(tdzero), tdzero)
            assert_equal(np.sign(tda).dtype, tda.dtype)

            # The ufuncs always produce native-endian results
            assert_ 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:41,代码来源:test_datetime.py

示例3: test_string_parser_variants

# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import positive [as 别名]
def test_string_parser_variants(self):
        # Allow space instead of 'T' between date and time
        assert_equal(np.array(['1980-02-29T01:02:03'], np.dtype('M8[s]')),
                     np.array(['1980-02-29 01:02:03'], np.dtype('M8[s]')))
        # Allow positive years
        assert_equal(np.array(['+1980-02-29T01:02:03'], np.dtype('M8[s]')),
                     np.array(['+1980-02-29 01:02:03'], np.dtype('M8[s]')))
        # Allow negative years
        assert_equal(np.array(['-1980-02-29T01:02:03'], np.dtype('M8[s]')),
                     np.array(['-1980-02-29 01:02:03'], np.dtype('M8[s]')))
        # UTC specifier
        with assert_warns(DeprecationWarning):
            assert_equal(
                np.array(['+1980-02-29T01:02:03'], np.dtype('M8[s]')),
                np.array(['+1980-02-29 01:02:03Z'], np.dtype('M8[s]')))
        with assert_warns(DeprecationWarning):
            assert_equal(
                np.array(['-1980-02-29T01:02:03'], np.dtype('M8[s]')),
                np.array(['-1980-02-29 01:02:03Z'], np.dtype('M8[s]')))
        # Time zone offset
        with assert_warns(DeprecationWarning):
            assert_equal(
                np.array(['1980-02-29T02:02:03'], np.dtype('M8[s]')),
                np.array(['1980-02-29 00:32:03-0130'], np.dtype('M8[s]')))
        with assert_warns(DeprecationWarning):
            assert_equal(
                np.array(['1980-02-28T22:32:03'], np.dtype('M8[s]')),
                np.array(['1980-02-29 00:02:03+01:30'], np.dtype('M8[s]')))
        with assert_warns(DeprecationWarning):
            assert_equal(
                np.array(['1980-02-29T02:32:03.506'], np.dtype('M8[s]')),
                np.array(['1980-02-29 00:32:03.506-02'], np.dtype('M8[s]')))
        with assert_warns(DeprecationWarning):
            assert_equal(np.datetime64('1977-03-02T12:30-0230'),
                         np.datetime64('1977-03-02T15:00')) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:37,代码来源:test_datetime.py

示例4: test_floor_division_signed_zero

# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import positive [as 别名]
def test_floor_division_signed_zero(self):
        # Check that the sign bit is correctly set when dividing positive and
        # negative zero by one.
        x = np.zeros(10)
        assert_equal(np.signbit(x//1), 0)
        assert_equal(np.signbit((-x)//1), 1) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:8,代码来源:test_umath.py

示例5: test_power_zero

# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import positive [as 别名]
def test_power_zero(self):
        # ticket #1271
        zero = np.array([0j])
        one = np.array([1+0j])
        cnan = np.array([complex(np.nan, np.nan)])
        # FIXME cinf not tested.
        #cinf = np.array([complex(np.inf, 0)])

        def assert_complex_equal(x, y):
            x, y = np.asarray(x), np.asarray(y)
            assert_array_equal(x.real, y.real)
            assert_array_equal(x.imag, y.imag)

        # positive powers
        for p in [0.33, 0.5, 1, 1.5, 2, 3, 4, 5, 6.6]:
            assert_complex_equal(np.power(zero, p), zero)

        # zero power
        assert_complex_equal(np.power(zero, 0), one)
        with np.errstate(invalid="ignore"):
            assert_complex_equal(np.power(zero, 0+1j), cnan)

            # negative power
            for p in [0.33, 0.5, 1, 1.5, 2, 3, 4, 5, 6.6]:
                assert_complex_equal(np.power(zero, -p), cnan)
            assert_complex_equal(np.power(zero, -1+0.2j), cnan) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:28,代码来源:test_umath.py

示例6: test_valid

# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import positive [as 别名]
def test_valid(self):
        valid_dtypes = [int, float, complex, object]
        for dtype in valid_dtypes:
            x = np.arange(5, dtype=dtype)
            result = np.positive(x)
            assert_equal(x, result, err_msg=str(dtype)) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:8,代码来源:test_umath.py

示例7: test_invalid

# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import positive [as 别名]
def test_invalid(self):
        with assert_raises(TypeError):
            np.positive(True)
        with assert_raises(TypeError):
            np.positive(np.datetime64('2000-01-01'))
        with assert_raises(TypeError):
            np.positive(np.array(['foo'], dtype=str))
        with assert_raises(TypeError):
            np.positive(np.array(['bar'], dtype=object)) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:11,代码来源:test_umath.py

示例8: test_pos_nan

# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import positive [as 别名]
def test_pos_nan():
    """Check np.nan is a positive nan."""
    assert_(np.signbit(np.nan) == 0) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:5,代码来源:test_umath.py

示例9: test_exceptions

# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import positive [as 别名]
def test_exceptions(self):
        a = np.ones(1, dtype=np.bool_)
        assert_raises(TypeError, np.negative, a)
        assert_raises(TypeError, np.positive, a)
        assert_raises(TypeError, np.subtract, a, a) 
开发者ID:birforce,项目名称:vnpy_crypto,代码行数:7,代码来源:test_umath.py

示例10: positive

# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import positive [as 别名]
def positive(x):
  return _scalar(lambda x: x, x) 
开发者ID:google,项目名称:trax,代码行数:4,代码来源:math_ops.py


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