本文整理汇总了Python中numpy.signedinteger方法的典型用法代码示例。如果您正苦于以下问题:Python numpy.signedinteger方法的具体用法?Python numpy.signedinteger怎么用?Python numpy.signedinteger使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类numpy
的用法示例。
在下文中一共展示了numpy.signedinteger方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: fit
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import signedinteger [as 别名]
def fit(self, X, y, sample_weight=None):
"""Fit the estimator.
Parameters
----------
X : {array-like, sparse matrix}, shape (n_samples, n_features)
Training data
y : numpy, shape (n_samples, n_targets)
Target values. Will be cast to X's dtype if necessary
sample_weight : array, shape (n_samples,)
Individual weights for each sample
"""
if np.issubdtype(y.dtype, np.signedinteger):
# classification
self.n_classes = np.unique(y).shape[0]
if self.n_classes == 2:
self.n_classes = 1
else:
# regression
self.n_classes = 1
示例2: safe_mask
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import signedinteger [as 别名]
def safe_mask(X, mask):
"""Return a mask which is safe to use on X.
Parameters
----------
X : {array-like, sparse matrix}
Data on which to apply mask.
mask : array
Mask to be used on X.
Returns
-------
mask
"""
mask = np.asarray(mask)
if np.issubdtype(mask.dtype, np.signedinteger):
return mask
if hasattr(X, "toarray"):
ind = np.arange(mask.shape[0])
mask = ind[mask]
return mask
示例3: _dtypes_are_compatible_for_bitwise_ops
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import signedinteger [as 别名]
def _dtypes_are_compatible_for_bitwise_ops(args):
if len(args) <= 1:
return True
is_signed = lambda dtype: lnp.issubdtype(dtype, onp.signedinteger)
width = lambda dtype: lnp.iinfo(dtype).bits
x, y = args
# `lnp.iinfo(dtype).bits` can't be called on bools, so we convert bools to
# ints.
if x == lnp.bool_:
x = lnp.int32
if y == lnp.bool_:
y = lnp.int32
if width(x) > width(y):
x, y = y, x
if x == lnp.uint32 and y == lnp.uint64:
return False
# The following condition seems a little ad hoc, but seems to capture what
# numpy actually implements.
return (
is_signed(x) == is_signed(y)
or (width(x) == 32 and width(y) == 32)
or (width(x) == 32 and width(y) == 64 and is_signed(y)))
示例4: promote_types
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import signedinteger [as 别名]
def promote_types(dtype1, dtype2):
"""
Get the smallest type to which the given scalar types can be cast.
Args:
dtype1 (builtin):
dtype2 (builtin):
Returns:
A builtin datatype or None.
"""
nptype1 = nptype_from_builtin(dtype1)
nptype2 = nptype_from_builtin(dtype2)
# Circumvent the undesirable np type promotion:
# >> np.promote_types(np.float32, np.int)
# dtype('float64')
if np.issubdtype(nptype1, np.floating) and np.issubdtype(nptype2, np.signedinteger):
nppromoted = nptype1
elif np.issubdtype(nptype2, np.floating) and np.issubdtype(
nptype1, np.signedinteger
):
nppromoted = nptype2
else:
nppromoted = np.promote_types(nptype1, nptype2)
return numpy_type_to_builtin_type(nppromoted)
示例5: convert_sklearn_label_encoder
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import signedinteger [as 别名]
def convert_sklearn_label_encoder(scope, operator, container):
op = operator.raw_operator
op_type = 'LabelEncoder'
attrs = {'name': scope.get_unique_operator_name(op_type)}
classes = op.classes_
if np.issubdtype(classes.dtype, np.floating):
attrs['keys_floats'] = classes
elif np.issubdtype(classes.dtype, np.signedinteger):
attrs['keys_int64s'] = classes
else:
attrs['keys_strings'] = np.array([s.encode('utf-8') for s in classes])
attrs['values_int64s'] = np.arange(len(classes))
container.add_node(op_type, operator.input_full_names,
operator.output_full_names, op_domain='ai.onnx.ml',
op_version=2, **attrs)
示例6: calculate_xgboost_classifier_output_shapes
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import signedinteger [as 别名]
def calculate_xgboost_classifier_output_shapes(operator):
check_input_and_output_numbers(operator, input_count_range=1, output_count_range=2)
check_input_and_output_types(operator, good_input_types=[FloatTensorType, Int64TensorType])
N = operator.inputs[0].type.shape[0]
xgb_node = operator.raw_operator
params = get_xgb_params(xgb_node)
booster = xgb_node.get_booster()
atts = booster.attributes()
ntrees = len(booster.get_dump(with_stats=True, dump_format = 'json'))
objective = params["objective"]
if objective == "binary:logistic":
ncl = 2
else:
ncl = ntrees // params['n_estimators']
if objective == "reg:logistic" and ncl == 1:
ncl = 2
classes = xgb_node.classes_
if (np.issubdtype(classes.dtype, np.floating) or
np.issubdtype(classes.dtype, np.signedinteger)):
operator.outputs[0].type = Int64TensorType(shape=[N])
else:
operator.outputs[0].type = StringTensorType(shape=[N])
operator.outputs[1].type = operator.outputs[1].type = FloatTensorType([N, ncl])
示例7: test_simple
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import signedinteger [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)
示例8: test_abstract
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import signedinteger [as 别名]
def test_abstract(self):
assert_(issubclass(np.number, numbers.Number))
assert_(issubclass(np.inexact, numbers.Complex))
assert_(issubclass(np.complexfloating, numbers.Complex))
assert_(issubclass(np.floating, numbers.Real))
assert_(issubclass(np.integer, numbers.Integral))
assert_(issubclass(np.signedinteger, numbers.Integral))
assert_(issubclass(np.unsignedinteger, numbers.Integral))
示例9: _assert_safe_casting
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import signedinteger [as 别名]
def _assert_safe_casting(cls, data, subarr):
"""
Ensure incoming data can be represented as ints.
"""
if not issubclass(data.dtype.type, np.signedinteger):
if not np.array_equal(data, subarr):
raise TypeError('Unsafe NumPy casting, you must '
'explicitly cast')
示例10: _safely_castable_to_int
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import signedinteger [as 别名]
def _safely_castable_to_int(dt):
"""Test whether the numpy data type `dt` can be safely cast to an int."""
int_size = np.dtype(int).itemsize
safe = ((np.issubdtype(dt, np.signedinteger) and dt.itemsize <= int_size) or
(np.issubdtype(dt, np.unsignedinteger) and dt.itemsize < int_size))
return safe
示例11: test_constructor6
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import signedinteger [as 别名]
def test_constructor6(self):
# infer dimensions and dtype from lists
indptr = [0, 1, 3, 3]
indices = [0, 5, 1, 2]
data = [1, 2, 3, 4]
csr = csr_matrix((data, indices, indptr))
assert_array_equal(csr.shape, (3,6))
assert_(np.issubdtype(csr.dtype, np.signedinteger))
示例12: test_single_query
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import signedinteger [as 别名]
def test_single_query(self):
d, i = self.kdtree.query(np.array([0,0,0]))
assert_(isinstance(d,float))
assert_(np.issubdtype(i, np.signedinteger))
示例13: _can_be_double
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import signedinteger [as 别名]
def _can_be_double(x):
"""
Return if the array can be safely converted to double.
That happens when the dtype is a float with the same size of
a double or narrower, or when is an integer that can be safely
converted to double (if the roundtrip conversion works).
"""
return ((np.issubdtype(x.dtype, np.floating) and
x.dtype.itemsize <= np.dtype(float).itemsize) or
(np.issubdtype(x.dtype, np.signedinteger) and
np.can_cast(x, float)))
示例14: coerce_to_dtype
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import signedinteger [as 别名]
def coerce_to_dtype(data, is_observed=False):
"""Summary"""
def reformat_tensor(result):
if is_observed:
result = torch.unsqueeze(result, dim=0)
result_shape = result.shape
if len(result_shape) == 2:
result = result.contiguous().view(size=result_shape + tuple([1, 1]))
elif len(result_shape) == 3:
result = result.contiguous().view(size=result_shape + tuple([1]))
#if len(result_shape) == 2:
# result = result.contiguous().view(size=result_shape + tuple([1]))
else:
result = torch.unsqueeze(torch.unsqueeze(result, dim=0), dim=1)
return result
dtype = type(data) ##TODO: do we need any additional shape checking?
if dtype is torch.Tensor: # to tensor
result = data.float()
elif dtype is np.ndarray: # to tensor
result = torch.tensor(data).float()
elif dtype is pd.DataFrame:
result = torch.tensor(data.values).float()
elif dtype in [float, int] or dtype.__base__ in [np.floating, np.signedinteger]: # to tensor
result = torch.tensor(data * np.ones(shape=(1, 1))).float()
elif dtype in [list, set, tuple, dict, str]: # to discrete
return data
else:
raise TypeError("Invalid input dtype {} - expected float, integer, np.ndarray, or torch var.".format(dtype))
result = reformat_tensor(result)
return result.to(device)
示例15: _get_type_of_series
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import signedinteger [as 别名]
def _get_type_of_series(series):
"""
Returns: type of the series (int16, int32, int64, int128 or str)
Raises:
ImproperIndecesTypeException: If the series
is not one of the expected types.
"""
if type(series[0]) == str:
return str
elif issubdtype(series.dtype, integer) or issubdtype(series.dtype, signedinteger):
return integer
raise ImproperIndecesTypeException(str(series.dtype))