本文整理匯總了Python中numpy.issubdtype方法的典型用法代碼示例。如果您正苦於以下問題:Python numpy.issubdtype方法的具體用法?Python numpy.issubdtype怎麽用?Python numpy.issubdtype使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類numpy
的用法示例。
在下文中一共展示了numpy.issubdtype方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: SetDistribution
# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import issubdtype [as 別名]
def SetDistribution(self, distinct_values):
"""This is all the values this column will ever see."""
assert self.all_distinct_values is None
# pd.isnull returns true for both np.nan and np.datetime64('NaT').
is_nan = pd.isnull(distinct_values)
contains_nan = np.any(is_nan)
dv_no_nan = distinct_values[~is_nan]
# NOTE: np.sort puts NaT values at beginning, and NaN values at end.
# For our purposes we always add any null value to the beginning.
vs = np.sort(np.unique(dv_no_nan))
if contains_nan and np.issubdtype(distinct_values.dtype, np.datetime64):
vs = np.insert(vs, 0, np.datetime64('NaT'))
elif contains_nan:
vs = np.insert(vs, 0, np.nan)
if self.distribution_size is not None:
assert len(vs) == self.distribution_size
self.all_distinct_values = vs
self.distribution_size = len(vs)
return self
示例2: test_basic_property
# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import issubdtype [as 別名]
def test_basic_property(self):
# Check A = L L^H
shapes = [(1, 1), (2, 2), (3, 3), (50, 50), (3, 10, 10)]
dtypes = (np.float32, np.float64, np.complex64, np.complex128)
for shape, dtype in itertools.product(shapes, dtypes):
np.random.seed(1)
a = np.random.randn(*shape)
if np.issubdtype(dtype, np.complexfloating):
a = a + 1j*np.random.randn(*shape)
t = list(range(len(shape)))
t[-2:] = -1, -2
a = np.matmul(a.transpose(t).conj(), a)
a = np.asarray(a, dtype=dtype)
c = np.linalg.cholesky(a)
b = np.matmul(c, c.transpose(t).conj())
assert_allclose(b, a,
err_msg="{} {}\n{}\n{}".format(shape, dtype, a, c),
atol=500 * a.shape[0] * np.finfo(dtype).eps)
示例3: _name_get
# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import issubdtype [as 別名]
def _name_get(dtype):
# provides dtype.name.__get__
if dtype.isbuiltin == 2:
# user dtypes don't promise to do anything special
return dtype.type.__name__
# Builtin classes are documented as returning a "bit name"
name = dtype.type.__name__
# handle bool_, str_, etc
if name[-1] == '_':
name = name[:-1]
# append bit counts to str, unicode, and void
if np.issubdtype(dtype, np.flexible) and not _isunsized(dtype):
name += "{}".format(dtype.itemsize * 8)
# append metadata to datetimes
elif dtype.type in (np.datetime64, np.timedelta64):
name += _datetime_metadata_str(dtype)
return name
示例4: _checksum
# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import issubdtype [as 別名]
def _checksum(fname, buffer_size=512 * 1024, dtype='uint64'):
# https://github.com/airware/buzzard/pull/39/#discussion_r239071556
dtype = np.dtype(dtype)
dtypesize = dtype.itemsize
assert buffer_size % dtypesize == 0
assert np.issubdtype(dtype, np.unsignedinteger)
acc = dtype.type(0)
with open(fname, "rb") as f:
with np.warnings.catch_warnings():
np.warnings.filterwarnings('ignore', r'overflow encountered')
for chunk in iter(lambda: f.read(buffer_size), b""):
head = np.frombuffer(chunk, dtype, count=len(chunk) // dtypesize)
head = np.add.reduce(head, dtype=dtype, initial=acc)
acc += head
tailsize = len(chunk) % dtypesize
if tailsize > 0:
# This should only be needed for file's tail
tail = chunk[-tailsize:] + b'\0' * (dtypesize - tailsize)
tail = np.frombuffer(tail, dtype)
acc += tail
return '{:016x}'.format(acc.item())
示例5: normalize_channels_parameter
# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import issubdtype [as 別名]
def normalize_channels_parameter(channels, channel_count):
if channels is None:
if channel_count == 1:
return [0], True
else:
return list(range(channel_count)), False
indices = np.arange(channel_count)
indices = indices[channels]
indices = np.atleast_1d(indices)
if isinstance(channels, slice):
return indices.tolist(), False
channels = np.asarray(channels)
if not np.issubdtype(channels.dtype, np.number):
raise TypeError('`channels` should be None or int or slice or list of int')
if channels.ndim == 0:
assert len(indices) == 1
return indices.tolist(), True
return indices.tolist(), False
示例6: __call__
# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import issubdtype [as 別名]
def __call__(self, df_or_series):
if isinstance(df_or_series, SERIES_TYPE):
if not np.issubdtype(df_or_series.dtype, np.number):
raise NotImplementedError('non-numeric type is not supported for now')
test_series = pd.Series([], dtype=df_or_series.dtype).describe(
percentiles=self._percentiles, include=self._include, exclude=self._exclude)
return self.new_series([df_or_series], shape=(len(test_series),),
dtype=test_series.dtype,
index_value=parse_index(test_series.index, store_data=True))
else:
test_inp_df = build_empty_df(df_or_series.dtypes)
test_df = test_inp_df.describe(
percentiles=self._percentiles, include=self._include, exclude=self._exclude)
for dtype in test_df.dtypes:
if not np.issubdtype(dtype, np.number):
raise NotImplementedError('non-numeric type is not supported for now')
return self.new_dataframe([df_or_series], shape=test_df.shape, dtypes=test_df.dtypes,
index_value=parse_index(test_df.index, store_data=True),
columns_value=parse_index(test_df.columns, store_data=True))
示例7: testAstype
# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import issubdtype [as 別名]
def testAstype(self):
arr = ones((10, 20, 30), chunk_size=3)
arr2 = arr.astype(np.int32)
arr2 = arr2.tiles()
self.assertEqual(arr2.shape, (10, 20, 30))
self.assertTrue(np.issubdtype(arr2.dtype, np.int32))
self.assertEqual(arr2.op.casting, 'unsafe')
with self.assertRaises(TypeError):
arr.astype(np.int32, casting='safe')
arr3 = arr.astype(arr.dtype, order='F')
self.assertTrue(arr3.flags['F_CONTIGUOUS'])
self.assertFalse(arr3.flags['C_CONTIGUOUS'])
arr3 = arr3.tiles()
self.assertEqual(arr3.chunks[0].order.value, 'F')
示例8: _AccumulateHistogram
# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import issubdtype [as 別名]
def _AccumulateHistogram(self, statistics=None, labels=None):
"""Accumulate histogram of binned statistic by label.
Args:
statistics: int32 np.array of shape [K, 1] of binned statistic
labels: int32 np.array of shape [K, 1] of labels
Returns:
nothing
"""
assert np.issubdtype(statistics.dtype, int)
if not statistics.size:
return
p = self.params
assert np.max(statistics) < self._histogram.shape[0], (
'Histogram shape too small %d vs %d' %
(np.max(statistics), self._histogram.shape[0]))
for l in range(p.metadata.NumClasses()):
indices = np.where(labels == l)[0]
for s in statistics[indices]:
self._histogram[s, l] += 1
示例9: __init__
# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import issubdtype [as 別名]
def __init__(self, arr=None, metadata=None, missing_id='<missing>',
groupings=None, substitute=True, weights=None, name=None):
super(self.__class__, self).__init__(arr, metadata, missing_id=missing_id, weights=weights, name=name)
self._nan = np.array([np.nan]).astype(int)[0]
if substitute and metadata is None:
self.arr, self.orig_type = self.substitute_values(self.arr)
elif substitute and metadata and not np.issubdtype(self.arr.dtype, np.integer):
# custom metadata has been passed in from external source, and must be converted to int
self.arr = self.arr.astype(int)
self.metadata = { int(k):v for k, v in metadata.items() }
self.metadata[self._nan] = missing_id
self._groupings = {}
if groupings is None:
for x in np.unique(self.arr):
self._groupings[x] = [x, x + 1, False]
else:
for x in np.unique(self.arr):
self._groupings[x] = list(groupings[x])
self._possible_groups = None
示例10: to_java_array
# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import issubdtype [as 別名]
def to_java_array(m):
'''
to_java_array(m) yields to_java_ints(m) if m is an array of integers and to_java_doubles(m) if
m is anything else. The numpy array m is tested via numpy.issubdtype(m.dtype, numpy.int64).
'''
if not hasattr(m, '__iter__'): return m
m = np.asarray(m)
if np.issubdtype(m.dtype, np.dtype(int).type) or all(isinstance(x, num.Integral) for x in m):
return to_java_ints(m)
else:
return to_java_doubles(m)
示例11: parse_type
# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import issubdtype [as 別名]
def parse_type(self, hdat, dataobj=None):
dtype = super(MGHImageType, self).parse_type(hdat, dataobj=dataobj)
if np.issubdtype(dtype, np.floating): dtype = np.float32
elif np.issubdtype(dtype, np.int8): dtype = np.int8
elif np.issubdtype(dtype, np.int16): dtype = np.int16
elif np.issubdtype(dtype, np.integer): dtype = np.int32
else: raise ValueError('Could not deduce appropriate MGH type for dtype %s' % dtype)
return dtype
示例12: output_indices
# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import issubdtype [as 別名]
def output_indices(ii):
ii = flattest(ii)
if (np.issubdtype(ii.dtype, np.dtype('bool').type)): ii = np.where(ii)[0]
return pimms.imm_array(ii)
示例13: __modify_schema__
# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import issubdtype [as 別名]
def __modify_schema__(cls, field_schema: Dict[str, Any]) -> None:
dt = cls._dtype
if dt is int or np.issubdtype(dt, np.integer):
items = {"type": "number", "multipleOf": 1.0}
elif dt is float or np.issubdtype(dt, np.floating):
items = {"type": "number"}
elif dt is str or np.issubdtype(dt, np.string_):
items = {"type": "string"}
elif dt is bool or np.issubdtype(dt, np.bool_):
items = {"type": "boolean"}
field_schema.update(type="array", items=items)
示例14: test_simple
# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import issubdtype [as 別名]
def test_simple():
tree_data, tree_clusters = phate.tree.gen_dla(n_branch=3)
phate_operator = phate.PHATE(knn=15, t=100, verbose=False)
tree_phate = phate_operator.fit_transform(tree_data)
assert tree_phate.shape == (tree_data.shape[0], 2)
clusters = phate.cluster.kmeans(phate_operator, n_clusters='auto')
assert np.issubdtype(clusters.dtype, np.signedinteger)
assert len(np.unique(clusters)) >= 2
assert len(clusters.shape) == 1
assert len(clusters) == tree_data.shape[0]
clusters = phate.cluster.kmeans(phate_operator, n_clusters=3)
assert np.issubdtype(clusters.dtype, np.signedinteger)
assert len(np.unique(clusters)) == 3
assert len(clusters.shape) == 1
assert len(clusters) == tree_data.shape[0]
phate_operator.fit(phate_operator.graph)
G = graphtools.Graph(
phate_operator.graph.kernel,
precomputed="affinity",
use_pygsp=True,
verbose=False,
)
phate_operator.fit(G)
G = pygsp.graphs.Graph(G.W)
phate_operator.fit(G)
phate_operator.fit(anndata.AnnData(tree_data))
with assert_raises_message(TypeError, "Expected phate_op to be of type PHATE. Got 1"):
phate.cluster.kmeans(1)
示例15: _name_arms
# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import issubdtype [as 別名]
def _name_arms(self, pred):
if self.choice_names is None:
return pred
else:
if not np.issubdtype(pred.dtype, np.integer):
pred = pred.astype(int)
return self.choice_names[pred]