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


Python numpy.ediff1d方法代碼示例

本文整理匯總了Python中numpy.ediff1d方法的典型用法代碼示例。如果您正苦於以下問題:Python numpy.ediff1d方法的具體用法?Python numpy.ediff1d怎麽用?Python numpy.ediff1d使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在numpy的用法示例。


在下文中一共展示了numpy.ediff1d方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: test_ediff1d

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import ediff1d [as 別名]
def test_ediff1d(self):
        zero_elem = np.array([])
        one_elem = np.array([1])
        two_elem = np.array([1, 2])

        assert_array_equal([], ediff1d(zero_elem))
        assert_array_equal([0], ediff1d(zero_elem, to_begin=0))
        assert_array_equal([0], ediff1d(zero_elem, to_end=0))
        assert_array_equal([-1, 0], ediff1d(zero_elem, to_begin=-1, to_end=0))
        assert_array_equal([], ediff1d(one_elem))
        assert_array_equal([1], ediff1d(two_elem))
        assert_array_equal([7,1,9], ediff1d(two_elem, to_begin=7, to_end=9))
        assert_array_equal([5,6,1,7,8], ediff1d(two_elem, to_begin=[5,6], to_end=[7,8]))
        assert_array_equal([1,9], ediff1d(two_elem, to_end=9))
        assert_array_equal([1,7,8], ediff1d(two_elem, to_end=[7,8]))
        assert_array_equal([7,1], ediff1d(two_elem, to_begin=7))
        assert_array_equal([5,6,1], ediff1d(two_elem, to_begin=[5,6])) 
開發者ID:Frank-qlu,項目名稱:recruit,代碼行數:19,代碼來源:test_arraysetops.py

示例2: testEdiff1d

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import ediff1d [as 別名]
def testEdiff1d(self):
        data = np.array([1, 2, 4, 7, 0])
        x = tensor(data, chunk_size=2)

        t = ediff1d(x)

        res = self.executor.execute_tensor(t, concat=True)[0]
        expected = np.ediff1d(data)
        np.testing.assert_equal(res, expected)

        to_begin = tensor(-99, chunk_size=2)
        to_end = tensor([88, 99], chunk_size=2)
        t = ediff1d(x, to_begin=to_begin, to_end=to_end)

        res = self.executor.execute_tensor(t, concat=True)[0]
        expected = np.ediff1d(data, to_begin=-99, to_end=np.array([88, 99]))
        np.testing.assert_equal(res, expected)

        data = [[1, 2, 4], [1, 6, 24]]

        t = ediff1d(tensor(data, chunk_size=2))

        res = self.executor.execute_tensor(t, concat=True)[0]
        expected = np.ediff1d(data)
        np.testing.assert_equal(res, expected) 
開發者ID:mars-project,項目名稱:mars,代碼行數:27,代碼來源:test_base_execute.py

示例3: integral_dt

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import ediff1d [as 別名]
def integral_dt(i, t):
   n = len(t)

   iavg = np.empty((n-1), np.float32)
   dt = np.empty((n-1), np.float32)

   iavg[0:n-1] = 0.5 * (i[0:n-1] + i[1:n])

   dt = np.ediff1d(t)

   integral = np.sum(iavg * dt)

   return integral


# helper functions 
開發者ID:cwebster2,項目名稱:pyMeteo,代碼行數:18,代碼來源:dynamics.py

示例4: get_duplicates

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import ediff1d [as 別名]
def get_duplicates(self, ids, tolerance=None, fast=True):
        ret = {}
        selection = self.ids_sorted(ids)
        values = np.array([self.value(i) for i in selection])
        if len(values) == 0:
            return ret
        diffs = np.ediff1d(values)

        for i in range(len(diffs)):
            idiff = diffs[i]
            if idiff < self.value_tol:
                ident1 = selection[i]
                ident2 = selection[i + 1]
                pcm_log.debug('Testing distances between %s and %s' % (str(ident1), str(ident2)))
                distance = self.distance(ident1, ident2)
                if distance < self.distance_tolerance:
                    pcm_log.debug('Distance %7.3f < %7.3f' % (distance, self.distance_tolerance))
                    ret[ident2] = ident1
        if len(ret) > 0:
            pcm_log.debug('Number of duplicates %d' % len(ret))
        return ret 
開發者ID:MaterialsDiscovery,項目名稱:PyChemia,代碼行數:23,代碼來源:ljcluster.py

示例5: _estimate_user_factors

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import ediff1d [as 別名]
def _estimate_user_factors(self, ITEM_factors_Y):

        profile_length = np.ediff1d(self.URM_train.indptr)
        profile_length_sqrt = np.sqrt(profile_length)

        # Estimating the USER_factors using ITEM_factors_Y
        if self.verbose:
            print("{}: Estimating user factors... ".format(self.algorithm_name))

        USER_factors = self.URM_train.dot(ITEM_factors_Y)

        #Divide every row for the sqrt of the profile length
        for user_index in range(self.n_users):

            if profile_length_sqrt[user_index] > 0:

                USER_factors[user_index, :] /= profile_length_sqrt[user_index]

        if self.verbose:
            print("{}: Estimating user factors... done!".format(self.algorithm_name))

        return USER_factors 
開發者ID:MaurizioFD,項目名稱:RecSys2019_DeepLearning_Evaluation,代碼行數:24,代碼來源:MatrixFactorization_Cython.py

示例6: __init__

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import ediff1d [as 別名]
def __init__(self, URM_train, batch_size):
        self.batch_size = batch_size

        URM_train = sps.csr_matrix(URM_train)
        self.n_users, self.n_items = URM_train.shape

        self.R = np.zeros((self.n_users, self.n_items), dtype=np.float32)

        self._users_with_interactions = np.ediff1d(URM_train.indptr)>=1
        self._users_with_interactions = np.arange(self.n_users, dtype=np.int64)[self._users_with_interactions]
        self._users_with_interactions = list(self._users_with_interactions)

        self.train_items, self.test_set = {}, {}

        for user_index in range(self.n_users):

            start_pos = URM_train.indptr[user_index]
            end_pos = URM_train.indptr[user_index+1]

            train_items = URM_train.indices[start_pos:end_pos]

            self.R[user_index][train_items] = 1
            self.train_items[user_index] = list(train_items) 
開發者ID:MaurizioFD,項目名稱:RecSys2019_DeepLearning_Evaluation,代碼行數:25,代碼來源:SpectralCF_RecommenderWrapper.py

示例7: cold_items_statistics

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import ediff1d [as 別名]
def cold_items_statistics(URM_train, URM_validation, URM_test, URM_test_negative):

    # Cold items experiment
    import  scipy.sparse as sps

    URM_train_validation = URM_train + URM_validation
    n_users, n_items = URM_train_validation.shape

    item_in_train_flag = np.ediff1d(sps.csc_matrix(URM_train_validation).indptr) > 0
    item_in_test_flag = np.ediff1d(sps.csc_matrix(URM_test).indptr) > 0

    test_item_not_in_train_flag = np.logical_and(item_in_test_flag, np.logical_not(item_in_train_flag))
    test_item_in_train_flag = np.logical_and(item_in_test_flag, item_in_train_flag)

    print("The test data contains {} unique items, {} ({:.2f} %) of them never appear in train data".format(
        item_in_test_flag.sum(),
        test_item_not_in_train_flag.sum(),
        test_item_not_in_train_flag.sum()/item_in_test_flag.sum()*100,
    )) 
開發者ID:MaurizioFD,項目名稱:RecSys2019_DeepLearning_Evaluation,代碼行數:21,代碼來源:run_IJCAI_17_DMF.py

示例8: fit

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import ediff1d [as 別名]
def fit(self, train_set, val_set=None):
        """Fit the model to observations.

        Parameters
        ----------
        train_set: :obj:`cornac.data.Dataset`, required
            User-Item preference data as well as additional modalities.

        val_set: :obj:`cornac.data.Dataset`, optional, default: None
            User-Item preference data for model selection purposes (e.g., early stopping).

        Returns
        -------
        self : object
        """
        Recommender.fit(self, train_set, val_set)

        self.item_pop = np.ediff1d(train_set.csc_matrix.indptr)

        return self 
開發者ID:PreferredAI,項目名稱:cornac,代碼行數:22,代碼來源:recom_most_pop.py

示例9: compute_rmssd

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import ediff1d [as 別名]
def compute_rmssd(peaks):

    rr = np.ediff1d(peaks, to_begin=0)
    rr[0] = np.mean(rr[1:])
    rmssd = np.sqrt(np.mean(rr ** 2))

    return rmssd 
開發者ID:neuropsychology,項目名稱:NeuroKit,代碼行數:9,代碼來源:tests_signal_fixpeaks.py

示例10: build_output_calibration_layer

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import ediff1d [as 別名]
def build_output_calibration_layer(output_calibration_input, model_config,
                                   dtype):
  """Creates a monotonic output calibration layer with inputs range [0, 1].

  Args:
    output_calibration_input: Input to the output calibration layer.
    model_config: Model configuration object describing model architecture.
      Should be one of the model configs in `tfl.configs`.
    dtype: dtype

  Returns:
    A `tfl.layers.PWLCalibration` instance.
  """
  # kernel format: bias followed by diffs between consecutive keypoint outputs.
  kernel_init_values = np.ediff1d(
      model_config.output_initialization,
      to_begin=model_config.output_initialization[0])
  input_keypoints = np.linspace(0.0, 1.0, num=len(kernel_init_values))
  kernel_initializer = tf.keras.initializers.Constant(kernel_init_values)
  kernel_regularizer = _output_calibration_regularizers(model_config)
  return pwl_calibration_layer.PWLCalibration(
      input_keypoints=input_keypoints,
      output_min=model_config.output_min,
      output_max=model_config.output_max,
      kernel_initializer=kernel_initializer,
      kernel_regularizer=kernel_regularizer,
      monotonicity=1,
      dtype=dtype,
      name=OUTPUT_CALIB_LAYER_NAME)(
          output_calibration_input) 
開發者ID:tensorflow,項目名稱:lattice,代碼行數:32,代碼來源:premade_lib.py

示例11: test_ediff1d_matrix

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import ediff1d [as 別名]
def test_ediff1d_matrix():
    # 2018-04-29: moved here from core.tests.test_arraysetops.
    assert(isinstance(np.ediff1d(np.matrix(1)), np.matrix))
    assert(isinstance(np.ediff1d(np.matrix(1), to_begin=1), np.matrix)) 
開發者ID:Frank-qlu,項目名稱:recruit,代碼行數:6,代碼來源:test_interaction.py

示例12: test_ediff1d_forbidden_type_casts

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import ediff1d [as 別名]
def test_ediff1d_forbidden_type_casts(self, ary, prepend, append):
        # verify resolution of gh-11490

        # specifically, raise an appropriate
        # Exception when attempting to append or
        # prepend with an incompatible type
        msg = 'cannot convert'
        with assert_raises_regex(ValueError, msg):
            ediff1d(ary=ary,
                    to_end=append,
                    to_begin=prepend) 
開發者ID:Frank-qlu,項目名稱:recruit,代碼行數:13,代碼來源:test_arraysetops.py

示例13: test_ediff1d_scalar_handling

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import ediff1d [as 別名]
def test_ediff1d_scalar_handling(self,
                                     ary,
                                     prepend,
                                     append,
                                     expected):
        # maintain backwards-compatibility
        # of scalar prepend / append behavior
        # in ediff1d following fix for gh-11490
        actual = np.ediff1d(ary=ary,
                            to_end=append,
                            to_begin=prepend)
        assert_equal(actual, expected) 
開發者ID:Frank-qlu,項目名稱:recruit,代碼行數:14,代碼來源:test_arraysetops.py

示例14: test_eff1d_casting

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import ediff1d [as 別名]
def test_eff1d_casting(self):
        # gh-12711
        x = np.array([1, 2, 4, 7, 0], dtype=np.int16)
        res = np.ediff1d(x, to_begin=-99, to_end=np.array([88, 99]))
        assert_equal(res, [-99,   1,   2,   3,  -7,  88,  99])
        assert_raises(ValueError, np.ediff1d, x, to_begin=(1<<20))
        assert_raises(ValueError, np.ediff1d, x, to_end=(1<<20)) 
開發者ID:Frank-qlu,項目名稱:recruit,代碼行數:9,代碼來源:test_regression.py

示例15: get_query_sizes

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import ediff1d [as 別名]
def get_query_sizes(self):
        """
        This method return the size of each query set.

        Returns
        -------
        sizes : numpy 1d array of int
            It is a ndarray of shape (n_queries,)
        """
        return np.ediff1d(self.query_offsets) 
開發者ID:hpclab,項目名稱:rankeval,代碼行數:12,代碼來源:dataset.py


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