当前位置: 首页>>代码示例>>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;未经允许,请勿转载。