本文整理匯總了Python中numpy.issubsctype方法的典型用法代碼示例。如果您正苦於以下問題:Python numpy.issubsctype方法的具體用法?Python numpy.issubsctype怎麽用?Python numpy.issubsctype使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類numpy
的用法示例。
在下文中一共展示了numpy.issubsctype方法的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: test_reconstruction
# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import issubsctype [as 別名]
def test_reconstruction(projector):
"""Test RayTransform for reconstruction."""
if (
isinstance(projector.geometry, odl.tomo.ConeBeamGeometry)
and projector.geometry.pitch != 0
):
pytest.skip('reconstruction with CG is hopeless with so few angles')
# Create Shepp-Logan phantom
vol = odl.phantom.shepp_logan(projector.domain, modified=True)
# Project data
projections = projector(vol)
# Reconstruct using ODL
recon = projector.domain.zero()
odl.solvers.conjugate_gradient_normal(projector, recon, projections,
niter=20)
# Make sure the result is somewhat close to the actual result
maxerr = vol.norm() * 0.5
if np.issubsctype(projector.domain.dtype, np.complexfloating):
# Error has double the amount of components practically
maxerr *= np.sqrt(2)
assert recon.dist(vol) < maxerr
示例2: _copy_array_if_base_present
# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import issubsctype [as 別名]
def _copy_array_if_base_present(a):
"""
Copy the array if its base points to a parent array.
"""
if a.base is not None:
return a.copy()
elif np.issubsctype(a, np.float32):
return np.array(a, dtype=np.double)
else:
return a
示例3: _copy_array_if_base_present
# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import issubsctype [as 別名]
def _copy_array_if_base_present(a):
"""
Copies the array if its base points to a parent array.
"""
if a.base is not None:
return a.copy()
elif np.issubsctype(a, np.float32):
return np.array(a, dtype=np.double)
else:
return a
示例4: is_numeric_dtype
# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import issubsctype [as 別名]
def is_numeric_dtype(dtype):
"""Return ``True`` if ``dtype`` is a numeric type."""
dtype = np.dtype(dtype)
return np.issubsctype(getattr(dtype, 'base', None), np.number)
示例5: is_int_dtype
# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import issubsctype [as 別名]
def is_int_dtype(dtype):
"""Return ``True`` if ``dtype`` is an integer type."""
dtype = np.dtype(dtype)
return np.issubsctype(getattr(dtype, 'base', None), np.integer)
示例6: is_real_floating_dtype
# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import issubsctype [as 別名]
def is_real_floating_dtype(dtype):
"""Return ``True`` if ``dtype`` is a real floating point type."""
dtype = np.dtype(dtype)
return np.issubsctype(getattr(dtype, 'base', None), np.floating)
示例7: is_complex_floating_dtype
# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import issubsctype [as 別名]
def is_complex_floating_dtype(dtype):
"""Return ``True`` if ``dtype`` is a complex floating point type."""
dtype = np.dtype(dtype)
return np.issubsctype(getattr(dtype, 'base', None), np.complexfloating)
示例8: slice
# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import issubsctype [as 別名]
def slice(self, columns_specifier):
"""Locate a subset of design matrix columns, specified symbolically.
A patsy design matrix has two levels of structure: the individual
columns (which are named), and the :ref:`terms <formulas>` in
the formula that generated those columns. This is a one-to-many
relationship: a single term may span several columns. This method
provides a user-friendly API for locating those columns.
(While we talk about columns here, this is probably most useful for
indexing into other arrays that are derived from the design matrix,
such as regression coefficients or covariance matrices.)
The `columns_specifier` argument can take a number of forms:
* A term name
* A column name
* A :class:`Term` object
* An integer giving a raw index
* A raw slice object
In all cases, a Python :func:`slice` object is returned, which can be
used directly for indexing.
Example::
y, X = dmatrices("y ~ a", demo_data("y", "a", nlevels=3))
betas = np.linalg.lstsq(X, y)[0]
a_betas = betas[X.design_info.slice("a")]
(If you want to look up a single individual column by name, use
``design_info.column_name_indexes[name]``.)
"""
if isinstance(columns_specifier, slice):
return columns_specifier
if np.issubsctype(type(columns_specifier), np.integer):
return slice(columns_specifier, columns_specifier + 1)
if (self.term_slices is not None
and columns_specifier in self.term_slices):
return self.term_slices[columns_specifier]
if columns_specifier in self.term_name_slices:
return self.term_name_slices[columns_specifier]
if columns_specifier in self.column_name_indexes:
idx = self.column_name_indexes[columns_specifier]
return slice(idx, idx + 1)
raise PatsyError("unknown column specified '%s'"
% (columns_specifier,))