本文整理汇总了Python中numpy.sctype2char方法的典型用法代码示例。如果您正苦于以下问题:Python numpy.sctype2char方法的具体用法?Python numpy.sctype2char怎么用?Python numpy.sctype2char使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类numpy
的用法示例。
在下文中一共展示了numpy.sctype2char方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_scalar_type
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import sctype2char [as 别名]
def test_scalar_type(self):
assert_equal(np.sctype2char(np.double), 'd')
assert_equal(np.sctype2char(np.int_), 'l')
assert_equal(np.sctype2char(np.unicode_), 'U')
assert_equal(np.sctype2char(np.bytes_), 'S')
示例2: test_other_type
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import sctype2char [as 别名]
def test_other_type(self):
assert_equal(np.sctype2char(float), 'd')
assert_equal(np.sctype2char(list), 'O')
assert_equal(np.sctype2char(np.ndarray), 'O')
示例3: test_third_party_scalar_type
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import sctype2char [as 别名]
def test_third_party_scalar_type(self):
from numpy.core._rational_tests import rational
assert_raises(KeyError, np.sctype2char, rational)
assert_raises(KeyError, np.sctype2char, rational(1))
示例4: test_array_instance
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import sctype2char [as 别名]
def test_array_instance(self):
assert_equal(np.sctype2char(np.array([1.0, 2.0])), 'd')
示例5: test_abstract_type
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import sctype2char [as 别名]
def test_abstract_type(self):
assert_raises(KeyError, np.sctype2char, np.floating)
示例6: prepare_node
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import sctype2char [as 别名]
def prepare_node(self, node, storage_map, compute_map):
# Postpone the ufunc building to the last minutes
# NumPy ufunc support only up to 31 inputs.
# But our c code support more.
if (len(node.inputs) < 32 and
(self.nfunc is None or
self.scalar_op.nin != len(node.inputs)) and
self.ufunc is None):
ufunc = numpy.frompyfunc(self.scalar_op.impl,
len(node.inputs),
self.scalar_op.nout)
if self.scalar_op.nin > 0:
# We can reuse it for many nodes
self.ufunc = ufunc
else:
node.tag.ufunc = ufunc
# Numpy ufuncs will sometimes perform operations in
# float16, in particular when the input is int8.
# This is not something that we want, and we do not
# do it in the C code, so we specify that the computation
# should be carried out in the returned dtype.
# This is done via the "sig" kwarg of the ufunc, its value
# should be something like "ff->f", where the characters
# represent the dtype of the inputs and outputs.
# NumPy 1.10.1 raise an error when giving the signature
# when the input is complex. So add it only when inputs is int.
out_dtype = node.outputs[0].dtype
if (out_dtype in float_dtypes and
isinstance(self.nfunc, numpy.ufunc) and
node.inputs[0].dtype in discrete_dtypes):
char = numpy.sctype2char(out_dtype)
sig = char * node.nin + '->' + char * node.nout
node.tag.sig = sig