本文整理匯總了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