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