当前位置: 首页>>代码示例>>Python>>正文


Python tensorflow.setdiff1d方法代码示例

本文整理汇总了Python中tensorflow.setdiff1d方法的典型用法代码示例。如果您正苦于以下问题:Python tensorflow.setdiff1d方法的具体用法?Python tensorflow.setdiff1d怎么用?Python tensorflow.setdiff1d使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在tensorflow的用法示例。


在下文中一共展示了tensorflow.setdiff1d方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: _testListDiff

# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import setdiff1d [as 别名]
def _testListDiff(self, x, y, out, idx):
    for dtype in _TYPES:
      if dtype == tf.string:
        x = [tf.compat.as_bytes(str(a)) for a in x]
        y = [tf.compat.as_bytes(str(a)) for a in y]
        out = [tf.compat.as_bytes(str(a)) for a in out]
      for diff_func in [tf.setdiff1d]:
        with self.test_session() as sess:
          x_tensor = tf.convert_to_tensor(x, dtype=dtype)
          y_tensor = tf.convert_to_tensor(y, dtype=dtype)
          out_tensor, idx_tensor = diff_func(x_tensor, y_tensor)
          tf_out, tf_idx = sess.run([out_tensor, idx_tensor])
        self.assertAllEqual(tf_out, out)
        self.assertAllEqual(tf_idx, idx)
        self.assertEqual(1, out_tensor.get_shape().ndims)
        self.assertEqual(1, idx_tensor.get_shape().ndims) 
开发者ID:tobegit3hub,项目名称:deep_image_model,代码行数:18,代码来源:listdiff_op_test.py

示例2: find_dup

# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import setdiff1d [as 别名]
def find_dup(a):
  """ Find the duplicated elements in 1-D a tensor.
  Args:
    a: 1-D tensor.
    
  Return:
    more_than_one_vals: duplicated value in a.
    indexes_in_a: duplicated value's index in a.
    dups_in_a: duplicated value with duplicate in a.
  """
  unique_a_vals, unique_idx = tf.unique(a)
  count_a_unique = tf.unsorted_segment_sum(tf.ones_like(a),
                                           unique_idx,
                                           tf.shape(a)[0])

  more_than_one = tf.greater(count_a_unique, 1)
  more_than_one_idx = tf.squeeze(tf.where(more_than_one))
  more_than_one_vals = tf.squeeze(tf.gather(unique_a_vals, more_than_one_idx))

  not_duplicated, _ = tf.setdiff1d(a, more_than_one_vals)
  dups_in_a, indexes_in_a = tf.setdiff1d(a, not_duplicated)

  return more_than_one_vals, indexes_in_a, dups_in_a 
开发者ID:Zehaos,项目名称:MobileNet,代码行数:25,代码来源:det_utils.py

示例3: setdiff1d

# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import setdiff1d [as 别名]
def setdiff1d(x, y, index_dtype=dtypes.int32, name=None):
  return gen_array_ops._list_diff(x, y, index_dtype, name) 
开发者ID:ryfeus,项目名称:lambda-packs,代码行数:4,代码来源:array_ops.py

示例4: sparse_mask

# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import setdiff1d [as 别名]
def sparse_mask(a, mask_indices, name=None):
  """Masks elements of `IndexedSlices`.

  Given an `IndexedSlices` instance `a`, returns another `IndexedSlices` that
  contains a subset of the slices of `a`. Only the slices at indices not
  specified in `mask_indices` are returned.

  This is useful when you need to extract a subset of slices in an
  `IndexedSlices` object.

  For example:

  ```python
  # `a` contains slices at indices [12, 26, 37, 45] from a large tensor
  # with shape [1000, 10]
  a.indices => [12, 26, 37, 45]
  tf.shape(a.values) => [4, 10]

  # `b` will be the subset of `a` slices at its second and third indices, so
  # we want to mask its first and last indices (which are at absolute
  # indices 12, 45)
  b = tf.sparse_mask(a, [12, 45])

  b.indices => [26, 37]
  tf.shape(b.values) => [2, 10]

  ```

  Args:
    a: An `IndexedSlices` instance.
    mask_indices: Indices of elements to mask.
    name: A name for the operation (optional).

  Returns:
    The masked `IndexedSlices` instance.
  """
  with ops.name_scope(name, "sparse_mask", [a, mask_indices]) as name:
    indices = a.indices
    out_indices, to_gather = setdiff1d(indices, mask_indices)
    out_values = gather(a.values, to_gather, name=name)
    return ops.IndexedSlices(out_values, out_indices, a.dense_shape) 
开发者ID:ryfeus,项目名称:lambda-packs,代码行数:43,代码来源:array_ops.py

示例5: get_neg_items_session

# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import setdiff1d [as 别名]
def get_neg_items_session(self, session_item_ids, candidate_samples, num_neg_samples):
        #Ignoring negative samples clicked within the session (keeps the order and repetition of candidate_samples)
        valid_samples_session, _ = tf.setdiff1d(candidate_samples, session_item_ids, index_dtype=tf.int64)

        #Generating a random list of negative samples for each click (with no repetition)
        session_clicks_neg_items = tf.map_fn(lambda click_id: tf.cond(tf.equal(click_id, tf.constant(0, tf.int64)), 
                                                                      lambda: tf.zeros(num_neg_samples, tf.int64),
                                                                      lambda: self.get_neg_items_click(valid_samples_session, num_neg_samples)
                                                                      )
                                             , session_item_ids)                                                     

        return session_clicks_neg_items 
开发者ID:gabrielspmoreira,项目名称:chameleon_recsys,代码行数:14,代码来源:nar_model.py

示例6: sparse_mask

# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import setdiff1d [as 别名]
def sparse_mask(a, mask_indices, name=None):
  """Masks elements of `IndexedSlices`.

  Given an `IndexedSlices` instance `a`, returns another `IndexedSlices` that
  contains a subset of the slices of `a`. Only the slices at indices not
  specified in `mask_indices` are returned.

  This is useful when you need to extract a subset of slices in an
  `IndexedSlices` object.

  For example:

  ```python
  # `a` contains slices at indices [12, 26, 37, 45] from a large tensor
  # with shape [1000, 10]
  a.indices => [12, 26, 37, 45]
  tf.shape(a.values) => [4, 10]

  # `b` will be the subset of `a` slices at its second and third indices, so
  # we want to mask its first and last indices (which are at absolute
  # indices 12, 45)
  b = tf.sparse_mask(a, [12, 45])

  b.indices => [26, 37]
  tf.shape(b.values) => [2, 10]

  ```

  Args:
    * `a`: An `IndexedSlices` instance.
    * `mask_indices`: Indices of elements to mask.
    * `name`: A name for the operation (optional).

  Returns:
    The masked `IndexedSlices` instance.
  """
  with ops.name_scope(name, "sparse_mask", [a, mask_indices]) as name:
    indices = a.indices
    out_indices, to_gather = setdiff1d(indices, mask_indices)
    out_values = gather(a.values, to_gather, name=name)
    return ops.IndexedSlices(out_values, out_indices, a.dense_shape) 
开发者ID:tobegit3hub,项目名称:deep_image_model,代码行数:43,代码来源:array_ops.py

示例7: sparse_mask

# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import setdiff1d [as 别名]
def sparse_mask(a, mask_indices, name=None):
  """Masks elements of `IndexedSlices`.

  Given an `IndexedSlices` instance `a`, returns another `IndexedSlices` that
  contains a subset of the slices of `a`. Only the slices at indices not
  specified in `mask_indices` are returned.

  This is useful when you need to extract a subset of slices in an
  `IndexedSlices` object.

  For example:

  ```python
  # `a` contains slices at indices [12, 26, 37, 45] from a large tensor
  # with shape [1000, 10]
  a.indices  # [12, 26, 37, 45]
  tf.shape(a.values)  # [4, 10]

  # `b` will be the subset of `a` slices at its second and third indices, so
  # we want to mask its first and last indices (which are at absolute
  # indices 12, 45)
  b = tf.sparse_mask(a, [12, 45])

  b.indices  # [26, 37]
  tf.shape(b.values)  # [2, 10]
  ```

  Args:
    a: An `IndexedSlices` instance.
    mask_indices: Indices of elements to mask.
    name: A name for the operation (optional).

  Returns:
    The masked `IndexedSlices` instance.
  """
  with ops.name_scope(name, "sparse_mask", [a, mask_indices]) as name:
    indices = a.indices
    out_indices, to_gather = setdiff1d(indices, mask_indices)
    out_values = gather(a.values, to_gather, name=name)
    return ops.IndexedSlices(out_values, out_indices, a.dense_shape) 
开发者ID:PacktPublishing,项目名称:Serverless-Deep-Learning-with-TensorFlow-and-AWS-Lambda,代码行数:42,代码来源:array_ops.py


注:本文中的tensorflow.setdiff1d方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。