本文整理汇总了Python中numpy.typeDict方法的典型用法代码示例。如果您正苦于以下问题:Python numpy.typeDict方法的具体用法?Python numpy.typeDict怎么用?Python numpy.typeDict使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类numpy
的用法示例。
在下文中一共展示了numpy.typeDict方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _get_output
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import typeDict [as 别名]
def _get_output(output, input, shape=None):
if shape is None:
shape = input.shape
if output is None:
output = numpy.zeros(shape, dtype=input.dtype.name)
return_value = output
elif type(output) in [type(type), type(numpy.zeros((4,)).dtype)]:
output = numpy.zeros(shape, dtype=output)
return_value = output
elif type(output) in string_types:
output = numpy.typeDict[output]
output = numpy.zeros(shape, dtype=output)
return_value = output
else:
if output.shape != shape:
raise RuntimeError("output shape not correct")
return_value = None
return output, return_value
示例2: _get_output
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import typeDict [as 别名]
def _get_output(output, input, shape=None):
if shape is None:
shape = input.shape
if output is None:
output = numpy.zeros(shape, dtype=input.dtype.name)
return_value = output
elif type(output) in [type(type), type(numpy.zeros((4,)).dtype)]:
output = numpy.zeros(shape, dtype=output)
return_value = output
elif type(output) == STRING_TYPE:
output = numpy.typeDict[output]
output = numpy.zeros(shape, dtype=output)
return_value = output
else:
if output.shape != shape:
raise RuntimeError("output shape not correct")
return_value = None
return output, return_value
示例3: __init__
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import typeDict [as 别名]
def __init__(self, info, image_defs):
"""
Parameters
----------
info : dict
"General information" from the PAR file (as returned by
`parse_PAR_header()`).
image_defs : array
Structured array with image definitions from the PAR file (as returned
by `parse_PAR_header()`).
"""
self.general_info = info
self.image_defs = image_defs
self._slice_orientation = None
# charge with basic properties to be able to use base class
# functionality
# dtype
dtype = np.typeDict[
'int'
+ str(self._get_unique_image_prop('image pixel size')[0])]
Header.__init__(self,
data_dtype=dtype,
shape=self.get_data_shape_in_file(),
zooms=self._get_zooms()
)
示例4: test_iinfo_long_values
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import typeDict [as 别名]
def test_iinfo_long_values(self):
for code in 'bBhH':
res = np.array(np.iinfo(code).max + 1, dtype=code)
tgt = np.iinfo(code).min
assert_(res == tgt)
for code in np.typecodes['AllInteger']:
res = np.array(np.iinfo(code).max, dtype=code)
tgt = np.iinfo(code).max
assert_(res == tgt)
for code in np.typecodes['AllInteger']:
res = np.typeDict[code](np.iinfo(code).max)
tgt = np.iinfo(code).max
assert_(res == tgt)
示例5: test_int_raise_behaviour
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import typeDict [as 别名]
def test_int_raise_behaviour(self):
def overflow_error_func(dtype):
np.typeDict[dtype](np.iinfo(dtype).max + 1)
for code in 'lLqQ':
assert_raises(OverflowError, overflow_error_func, code)
示例6: dtype_for
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import typeDict [as 别名]
def dtype_for(t):
""" return my dtype mapping, whether number or name """
if t in dtype_dict:
return dtype_dict[t]
return np.typeDict.get(t, t)
示例7: c2f
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import typeDict [as 别名]
def c2f(r, i, ctype_name):
"""
Convert strings to complex number instance with specified numpy type.
"""
ftype = c2f_dict[ctype_name]
return np.typeDict[ctype_name](ftype(r) + 1j * ftype(i))
示例8: dtype_for
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import typeDict [as 别名]
def dtype_for(t):
if t in dtype_dict:
return dtype_dict[t]
return np.typeDict[t]
示例9: test_rmul_scalar
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import typeDict [as 别名]
def test_rmul_scalar(self):
def check(dtype):
dat = self.dat_dtypes[dtype]
datsp = self.datsp_dtypes[dtype]
assert_array_equal(2*dat,(2*datsp).todense())
assert_array_equal(17.3*dat,(17.3*datsp).todense())
for dtype in self.checked_dtypes:
fails = ((dtype == np.typeDict['int']) and
(self.__class__ == TestLIL or
self.__class__ == TestDOK))
msg = "LIL and DOK type's __rmul__ method has problems with int data."
yield dec.knownfailureif(fails, msg)(check), dtype
示例10: _get_output
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import typeDict [as 别名]
def _get_output(output, input, shape=None):
if shape is None:
shape = input.shape
if output is None:
output = numpy.zeros(shape, dtype=input.dtype.name)
elif type(output) in [type(type), type(numpy.zeros((4,)).dtype)]:
output = numpy.zeros(shape, dtype=output)
elif type(output) in string_types:
output = numpy.typeDict[output]
output = numpy.zeros(shape, dtype=output)
elif output.shape != shape:
raise RuntimeError("output shape not correct")
return output