text.gather_with_default
Stay organized with collections
Save and categorize content based on your preferences.
Gather slices with indices=-1
mapped to default
.
text.gather_with_default(
params, indices, default, name=None, axis=0
)
This operation is similar to tf.gather()
, except that any value of -1
in indices
will be mapped to default
. Example:
gather_with_default(['a', 'b', 'c', 'd'], [2, 0, -1, 2, -1], '_')
<tf.Tensor: shape=(5,), dtype=string,
numpy=array([b'c', b'a', b'_', b'c', b'_'], dtype=object)>
Args |
params
|
The Tensor from which to gather values. Must be at least rank
axis + 1 .
|
indices
|
The index Tensor . Must have dtype int32 or int64 , and values
must be in the range [-1, params.shape[axis]) .
|
default
|
The value to use when indices is -1 . default.shape must
be equal to params.shape[axis + 1:] .
|
name
|
A name for the operation (optional).
|
axis
|
The axis in params to gather indices from. Must be a scalar
int32 or int64 . Supports negative indices.
|
Returns |
A Tensor with the same type as param , and with shape
params.shape[:axis] + indices.shape + params.shape[axis + 1:] .
|
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.
Last updated 2024-07-19 UTC.
[{
"type": "thumb-down",
"id": "missingTheInformationINeed",
"label":"Missing the information I need"
},{
"type": "thumb-down",
"id": "tooComplicatedTooManySteps",
"label":"Too complicated / too many steps"
},{
"type": "thumb-down",
"id": "outOfDate",
"label":"Out of date"
},{
"type": "thumb-down",
"id": "samplesCodeIssue",
"label":"Samples / code issue"
},{
"type": "thumb-down",
"id": "otherDown",
"label":"Other"
}]
[{
"type": "thumb-up",
"id": "easyToUnderstand",
"label":"Easy to understand"
},{
"type": "thumb-up",
"id": "solvedMyProblem",
"label":"Solved my problem"
},{
"type": "thumb-up",
"id": "otherUp",
"label":"Other"
}]
{"lastModified": "Last updated 2024-07-19 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-07-19 UTC."],[],[]]