tf.keras.ops.slice_update
Stay organized with collections
Save and categorize content based on your preferences.
Update an input by slicing in a tensor of updated values.
tf.keras.ops.slice_update(
inputs, start_indices, updates
)
At a high level, this operation does
inputs[start_indices: start_indices + updates.shape] = updates
.
Assume inputs is a tensor of shape (D0, D1, ..., Dn)
,
start_indices
must be a list/tuple of n integers, specifying the starting
indices. updates
must have the same rank as inputs
, and the size of each
dim must not exceed Di - start_indices[i]
. For example, if we have 2D
inputs inputs = np.zeros((5, 5))
, and we want to update the intersection
of last 2 rows and last 2 columns as 1, i.e.,
inputs[3:, 3:] = np.ones((2, 2))
, then we can use the code below:
inputs = np.zeros((5, 5))
start_indices = [3, 3]
updates = np.ones((2, 2))
inputs = keras.ops.slice_update(inputs, start_indices, updates)
Args |
inputs
|
A tensor, the tensor to be updated.
|
start_indices
|
A list/tuple of shape (inputs.ndim,) , specifying
the starting indices for updating.
|
updates
|
A tensor, the new values to be put to inputs at indices .
updates must have the same rank as inputs .
|
Returns |
A tensor, has the same shape and dtype as inputs .
|
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates. Some content is licensed under the numpy license.
Last updated 2024-06-07 UTC.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2024-06-07 UTC."],[],[]]