本文整理汇总了Python中numpy.core._rational_tests.rational方法的典型用法代码示例。如果您正苦于以下问题:Python _rational_tests.rational方法的具体用法?Python _rational_tests.rational怎么用?Python _rational_tests.rational使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类numpy.core._rational_tests
的用法示例。
在下文中一共展示了_rational_tests.rational方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_ufunc_custom_out
# 需要导入模块: from numpy.core import _rational_tests [as 别名]
# 或者: from numpy.core._rational_tests import rational [as 别名]
def test_ufunc_custom_out(self):
# Test ufunc with built in input types and custom output type
a = np.array([0, 1, 2], dtype='i8')
b = np.array([0, 1, 2], dtype='i8')
c = np.empty(3, dtype=_rational_tests.rational)
# Output must be specified so numpy knows what
# ufunc signature to look for
result = _rational_tests.test_add(a, b, c)
target = np.array([0, 2, 4], dtype=_rational_tests.rational)
assert_equal(result, target)
# no output type should raise TypeError
with assert_raises(TypeError):
_rational_tests.test_add(a, b)
示例2: test_custom_ufunc
# 需要导入模块: from numpy.core import _rational_tests [as 别名]
# 或者: from numpy.core._rational_tests import rational [as 别名]
def test_custom_ufunc(self):
a = np.array(
[_rational_tests.rational(1, 2),
_rational_tests.rational(1, 3),
_rational_tests.rational(1, 4)],
dtype=_rational_tests.rational)
b = np.array(
[_rational_tests.rational(1, 2),
_rational_tests.rational(1, 3),
_rational_tests.rational(1, 4)],
dtype=_rational_tests.rational)
result = _rational_tests.test_add_rationals(a, b)
expected = np.array(
[_rational_tests.rational(1),
_rational_tests.rational(2, 3),
_rational_tests.rational(1, 2)],
dtype=_rational_tests.rational)
assert_equal(result, expected)
示例3: test_custom_ufunc_forced_sig
# 需要导入模块: from numpy.core import _rational_tests [as 别名]
# 或者: from numpy.core._rational_tests import rational [as 别名]
def test_custom_ufunc_forced_sig(self):
# gh-9351 - looking for a non-first userloop would previously hang
with assert_raises(TypeError):
np.multiply(_rational_tests.rational(1), 1,
signature=(_rational_tests.rational, int, None))
示例4: test_rational_dtype
# 需要导入模块: from numpy.core import _rational_tests [as 别名]
# 或者: from numpy.core._rational_tests import rational [as 别名]
def test_rational_dtype():
# test for bug gh-5719
a = np.array([1111], dtype=rational).astype
assert_raises(OverflowError, a, 'int8')
# test that dtype detection finds user-defined types
x = rational(1)
assert_equal(np.array([x,x]).dtype, np.dtype(rational))