當前位置: 首頁>>代碼示例>>Python>>正文


Python numpy.signedinteger方法代碼示例

本文整理匯總了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 
開發者ID:PacktPublishing,項目名稱:Mastering-Elasticsearch-7.0,代碼行數:24,代碼來源:gradient_boosting.py

示例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 
開發者ID:PacktPublishing,項目名稱:Mastering-Elasticsearch-7.0,代碼行數:25,代碼來源:__init__.py

示例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))) 
開發者ID:google,項目名稱:trax,代碼行數:24,代碼來源:lax_numpy_test.py

示例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) 
開發者ID:apple,項目名稱:coremltools,代碼行數:27,代碼來源:type_mapping.py

示例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) 
開發者ID:onnx,項目名稱:sklearn-onnx,代碼行數:18,代碼來源:label_encoder.py

示例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]) 
開發者ID:onnx,項目名稱:onnxmltools,代碼行數:27,代碼來源:Classifier.py

示例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) 
開發者ID:KrishnaswamyLab,項目名稱:PHATE,代碼行數:30,代碼來源:test.py

示例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)) 
開發者ID:Frank-qlu,項目名稱:recruit,代碼行數:12,代碼來源:test_abc.py

示例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') 
開發者ID:Frank-qlu,項目名稱:recruit,代碼行數:10,代碼來源:numeric.py

示例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 
開發者ID:ryfeus,項目名稱:lambda-packs,代碼行數:8,代碼來源:measurements.py

示例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)) 
開發者ID:Relph1119,項目名稱:GraphicDesignPatternByPython,代碼行數:10,代碼來源:test_base.py

示例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)) 
開發者ID:Relph1119,項目名稱:GraphicDesignPatternByPython,代碼行數:6,代碼來源:test_kdtree.py

示例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))) 
開發者ID:vnmabus,項目名稱:dcor,代碼行數:15,代碼來源:_utils.py

示例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) 
開發者ID:AI-DI,項目名稱:Brancher,代碼行數:34,代碼來源:utilities.py

示例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)) 
開發者ID:GeoDaCenter,項目名稱:spatial_access,代碼行數:16,代碼來源:p2p.py


注:本文中的numpy.signedinteger方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。