Add an example of an IndexedSlices
PiperOrigin-RevId: 346108545 Change-Id: I9ba894e07e2f2d0c3884c1834a5a2c2308451a91
This commit is contained in:
parent
03d7d7667f
commit
4479e94258
@ -81,6 +81,18 @@ class IndexedSlices(internal.NativeObject, composite_tensor.CompositeTensor):
|
||||
gradients for operations that have sparse gradients
|
||||
(e.g. `tf.gather`).
|
||||
|
||||
>>> v = tf.Variable([[0.,1, 2], [2, 3, 4], [4, 5, 6], [6, 7, 8]])
|
||||
>>> with tf.GradientTape() as tape:
|
||||
... r = tf.gather(v, [1,3])
|
||||
>>> index_slices = tape.gradient(r,v)
|
||||
>>> index_slices
|
||||
<...IndexedSlices object ...>
|
||||
>>> index_slices.indices.numpy()
|
||||
array([1, 3], dtype=int32)
|
||||
>>> index_slices.values.numpy()
|
||||
array([[1., 1., 1.],
|
||||
[1., 1., 1.]], dtype=float32)
|
||||
|
||||
Contrast this representation with
|
||||
`tf.sparse.SparseTensor`,
|
||||
which uses multi-dimensional indices and scalar values.
|
||||
|
Loading…
x
Reference in New Issue
Block a user