tf.sparse_segment_sum()

tf.sparse_segment_sum(data, indices, segment_ids, name=None) Computes the sum along sparse segments of a tensor. Read the section on Segmentation for an explanation of segments. Like SegmentSum, but segment_ids can have rank less than data's first dimension, selecting a subset of dimension 0, specified by indices. For example: c = tf.constant([[1,2,3,4], [-1,-2,-3,-4], [5,6,7,8]]) # Select two rows, one segment. tf.sparse_segment_sum(c, tf.constant([0, 1]), tf.constant([0, 0])) ==> [[0 0

tf.sparse_segment_sqrt_n()

tf.sparse_segment_sqrt_n(data, indices, segment_ids, name=None) Computes the sum along sparse segments of a tensor divided by the sqrt of N. N is the size of the segment being reduced. Read the section on Segmentation for an explanation of segments. Args: data: A Tensor. Must be one of the following types: float32, float64. indices: A Tensor. Must be one of the following types: int32, int64. A 1-D tensor. Has same rank as segment_ids. segment_ids: A Tensor of type int32. A 1-D tensor. Value

tf.sparse_segment_mean()

tf.sparse_segment_mean(data, indices, segment_ids, name=None) Computes the mean along sparse segments of a tensor. Read the section on Segmentation for an explanation of segments. Like SegmentMean, but segment_ids can have rank less than data's first dimension, selecting a subset of dimension 0, specified by indices. Args: data: A Tensor. Must be one of the following types: float32, float64. indices: A Tensor. Must be one of the following types: int32, int64. A 1-D tensor. Has same rank as s

tf.sparse_retain()

tf.sparse_retain(sp_input, to_retain) Retains specified non-empty values within a SparseTensor. For example, if sp_input has shape [4, 5] and 4 non-empty string values: [0, 1]: a [0, 3]: b [2, 0]: c [3, 1]: d and to_retain = [True, False, False, True], then the output will be a SparseTensor of shape [4, 5] with 2 non-empty values: [0, 1]: a [3, 1]: d Args: sp_input: The input SparseTensor with N non-empty elements. to_retain: A bool vector of length N with M true values. Returns: A Spars

tf.sparse_reshape()

tf.sparse_reshape(sp_input, shape, name=None) Reshapes a SparseTensor to represent values in a new dense shape. This operation has the same semantics as reshape on the represented dense tensor. The indices of non-empty values in sp_input are recomputed based on the new dense shape, and a new SparseTensor is returned containing the new indices and new shape. The order of non-empty values in sp_input is unchanged. If one component of shape is the special value -1, the size of that dimension is c

tf.sparse_reset_shape()

tf.sparse_reset_shape(sp_input, new_shape=None) Resets the shape of a SparseTensor with indices and values unchanged. If new_shape is None, returns a copy of sp_input with its shape reset to the tight bounding box of sp_input. If new_shape is provided, then it must be larger or equal in all dimensions compared to the shape of sp_input. When this condition is met, the returned SparseTensor will have its shape reset to new_shape and its indices and values unchanged from that of sp_input. For exa

tf.sparse_reorder()

tf.sparse_reorder(sp_input, name=None) Reorders a SparseTensor into the canonical, row-major ordering. Note that by convention, all sparse ops preserve the canonical ordering along increasing dimension number. The only time ordering can be violated is during manual manipulation of the indices and values to add entries. Reordering does not affect the shape of the SparseTensor. For example, if sp_input has shape [4, 5] and indices / values: [0, 3]: b [0, 1]: a [3, 1]: d [2, 0]: c then the outpu

tf.sparse_reduce_sum_sparse()

tf.sparse_reduce_sum_sparse(sp_input, reduction_axes=None, keep_dims=False) Computes the sum of elements across dimensions of a SparseTensor. This Op takes a SparseTensor and is the sparse counterpart to tf.reduce_sum(). In contrast to SparseReduceSum, this Op returns a SparseTensor. Reduces sp_input along the dimensions given in reduction_axes. Unless keep_dims is true, the rank of the tensor is reduced by 1 for each entry in reduction_axes. If keep_dims is true, the reduced dimensions are re

tf.sparse_reduce_sum()

tf.sparse_reduce_sum(sp_input, reduction_axes=None, keep_dims=False) Computes the sum of elements across dimensions of a SparseTensor. This Op takes a SparseTensor and is the sparse counterpart to tf.reduce_sum(). In particular, this Op also returns a dense Tensor instead of a sparse one. Reduces sp_input along the dimensions given in reduction_axes. Unless keep_dims is true, the rank of the tensor is reduced by 1 for each entry in reduction_axes. If keep_dims is true, the reduced dimensions a

tf.sparse_placeholder()

tf.sparse_placeholder(dtype, shape=None, name=None) Inserts a placeholder for a sparse tensor that will be always fed. Important: This sparse tensor will produce an error if evaluated. Its value must be fed using the feed_dict optional argument to Session.run(), Tensor.eval(), or Operation.run(). For example: x = tf.sparse_placeholder(tf.float32) y = tf.sparse_reduce_sum(x) with tf.Session() as sess: print(sess.run(y)) # ERROR: will fail because x was not fed. indices = np.array([[3, 2,