本文整理汇总了Python中numpy.single方法的典型用法代码示例。如果您正苦于以下问题:Python numpy.single方法的具体用法?Python numpy.single怎么用?Python numpy.single使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类numpy
的用法示例。
在下文中一共展示了numpy.single方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: do
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import single [as 别名]
def do(self, a, b, tags):
d = linalg.det(a)
(s, ld) = linalg.slogdet(a)
if asarray(a).dtype.type in (single, double):
ad = asarray(a).astype(double)
else:
ad = asarray(a).astype(cdouble)
ev = linalg.eigvals(ad)
assert_almost_equal(d, multiply.reduce(ev, axis=-1))
assert_almost_equal(s * np.exp(ld), multiply.reduce(ev, axis=-1))
s = np.atleast_1d(s)
ld = np.atleast_1d(ld)
m = (s != 0)
assert_almost_equal(np.abs(s[m]), 1)
assert_equal(ld[~m], -inf)
示例2: test_floating_overflow
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import single [as 别名]
def test_floating_overflow(self):
""" Strings containing an unrepresentable float overflow """
fhalf = np.half('1e10000')
assert_equal(fhalf, np.inf)
fsingle = np.single('1e10000')
assert_equal(fsingle, np.inf)
fdouble = np.double('1e10000')
assert_equal(fdouble, np.inf)
flongdouble = assert_warns(RuntimeWarning, np.longdouble, '1e10000')
assert_equal(flongdouble, np.inf)
fhalf = np.half('-1e10000')
assert_equal(fhalf, -np.inf)
fsingle = np.single('-1e10000')
assert_equal(fsingle, -np.inf)
fdouble = np.double('-1e10000')
assert_equal(fdouble, -np.inf)
flongdouble = assert_warns(RuntimeWarning, np.longdouble, '-1e10000')
assert_equal(flongdouble, -np.inf)
示例3: do
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import single [as 别名]
def do(self, a, b):
d = linalg.det(a)
(s, ld) = linalg.slogdet(a)
if asarray(a).dtype.type in (single, double):
ad = asarray(a).astype(double)
else:
ad = asarray(a).astype(cdouble)
ev = linalg.eigvals(ad)
assert_almost_equal(d, multiply.reduce(ev, axis=-1))
assert_almost_equal(s * np.exp(ld), multiply.reduce(ev, axis=-1))
s = np.atleast_1d(s)
ld = np.atleast_1d(ld)
m = (s != 0)
assert_almost_equal(np.abs(s[m]), 1)
assert_equal(ld[~m], -inf)
示例4: align
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import single [as 别名]
def align(image, points):
"""
:param image:
:param points:
:return: aligned image
"""
# alignment
origin_point = np.require(np.array(points).reshape((4, 2)), dtype=np.single)
height = int(max(np.linalg.norm(origin_point[0] - origin_point[1]), np.linalg.norm(origin_point[2] - origin_point[3])))
width = int(max(np.linalg.norm(origin_point[0] - origin_point[3]), np.linalg.norm(origin_point[1] - origin_point[2])))
target_point = np.float32([[0, 0], [0, height], [width, height], [width, 0]])
map_matrix = cv2.getPerspectiveTransform(origin_point, target_point)
cols = width + 1
rows = height + 1
color = cv2.warpPerspective(image, map_matrix, (cols, rows))
return color
示例5: test_mode_raw
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import single [as 别名]
def test_mode_raw(self):
# The factorization is not unique and varies between libraries,
# so it is not possible to check against known values. Functional
# testing is a possibility, but awaits the exposure of more
# of the functions in lapack_lite. Consequently, this test is
# very limited in scope. Note that the results are in FORTRAN
# order, hence the h arrays are transposed.
a = array([[1, 2], [3, 4], [5, 6]], dtype=np.double)
b = a.astype(np.single)
# Test double
h, tau = linalg.qr(a, mode='raw')
assert_(h.dtype == np.double)
assert_(tau.dtype == np.double)
assert_(h.shape == (2, 3))
assert_(tau.shape == (2,))
h, tau = linalg.qr(a.T, mode='raw')
assert_(h.dtype == np.double)
assert_(tau.dtype == np.double)
assert_(h.shape == (3, 2))
assert_(tau.shape == (2,))
示例6: test_precision
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import single [as 别名]
def test_precision(self):
# not looping results in a useful stack trace upon failure
self.do_precision(np.half, np.single)
self.do_precision(np.half, np.double)
self.do_precision(np.half, np.longdouble)
self.do_precision(np.single, np.double)
self.do_precision(np.single, np.longdouble)
self.do_precision(np.double, np.longdouble)
示例7: assert_almost_equal
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import single [as 别名]
def assert_almost_equal(a, b, single_decimal=6, double_decimal=12, **kw):
if asarray(a).dtype.type in (single, csingle):
decimal = single_decimal
else:
decimal = double_decimal
old_assert_almost_equal(a, b, decimal=decimal, **kw)
示例8: get_real_dtype
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import single [as 别名]
def get_real_dtype(dtype):
return {single: single, double: double,
csingle: single, cdouble: double}[dtype]
示例9: get_complex_dtype
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import single [as 别名]
def get_complex_dtype(dtype):
return {single: csingle, double: cdouble,
csingle: csingle, cdouble: cdouble}[dtype]
示例10: get_rtol
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import single [as 别名]
def get_rtol(dtype):
# Choose a safe rtol
if dtype in (single, csingle):
return 1e-5
else:
return 1e-11
# used to categorize tests
示例11: test_sum_initial
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import single [as 别名]
def test_sum_initial(self):
# Integer, single axis
assert_equal(np.sum([3], initial=2), 5)
# Floating point
assert_almost_equal(np.sum([0.2], initial=0.1), 0.3)
# Multiple non-adjacent axes
assert_equal(np.sum(np.ones((2, 3, 5), dtype=np.int64), axis=(0, 2), initial=2),
[12, 12, 12])
示例12: test_floating
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import single [as 别名]
def test_floating(self):
# Ticket #640, floats from string
fsingle = np.single('1.234')
fdouble = np.double('1.234')
flongdouble = np.longdouble('1.234')
assert_almost_equal(fsingle, 1.234)
assert_almost_equal(fdouble, 1.234)
assert_almost_equal(flongdouble, 1.234)
示例13: test_singleton
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import single [as 别名]
def test_singleton(self):
ftype = finfo(single)
ftype2 = finfo(single)
assert_equal(id(ftype), id(ftype2))
示例14: test_compress_small_type
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import single [as 别名]
def test_compress_small_type(self):
# Ticket #789, changeset 5217.
# compress with out argument segfaulted if cannot cast safely
import numpy as np
a = np.array([[1, 2], [3, 4]])
b = np.zeros((2, 1), dtype=np.single)
try:
a.compress([True, False], axis=1, out=b)
raise AssertionError("compress with an out which cannot be "
"safely casted should not return "
"successfully")
except TypeError:
pass
示例15: extract_rmsmap
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import single [as 别名]
def extract_rmsmap(fbin, out_folder=None, force=False):
"""
Wrapper for rmsmap that outputs _ibl_ephysRmsMap and _ibl_ephysSpectra ALF files
:param fbin: binary file in spike glx format (will look for attached metatdata)
:param out_folder: folder in which to store output ALF files. Default uses the folder in which
the `fbin` file lives.
:param force: do not re-extract if all ALF files already exist
:param label: string or list of strings that will be appended to the filename before extension
:return: None
"""
_logger.info(str(fbin))
sglx = spikeglx.Reader(fbin)
# check if output ALF files exist already:
if out_folder is None:
out_folder = Path(fbin).parent
else:
out_folder = Path(out_folder)
alf_object_time = f'_iblqc_ephysTimeRms{sglx.type.upper()}'
alf_object_freq = f'_iblqc_ephysSpectralDensity{sglx.type.upper()}'
if alf.io.exists(out_folder, alf_object_time) and \
alf.io.exists(out_folder, alf_object_freq) and not force:
_logger.warning(f'{fbin.name} QC already exists, skipping. Use force option to override')
return
# crunch numbers
rms = rmsmap(fbin)
# output ALF files, single precision with the optional label as suffix before extension
if not out_folder.exists():
out_folder.mkdir()
tdict = {'rms': rms['TRMS'].astype(np.single), 'timestamps': rms['tscale'].astype(np.single)}
fdict = {'power': rms['spectral_density'].astype(np.single),
'freqs': rms['fscale'].astype(np.single)}
out_time = alf.io.save_object_npy(out_folder, object=alf_object_time, dico=tdict)
out_freq = alf.io.save_object_npy(out_folder, object=alf_object_freq, dico=fdict)
return out_time + out_freq