How to replace particular values based on condition by using tf.where()How can I safely create a nested directory?Does Python have a ternary conditional operator?How to get the current time in PythonHow can I make a time delay in Python?How do I sort a dictionary by value?How to make a flat list out of list of listsHow do I pass a variable by reference?How do I list all files of a directory?How to access environment variable values?Select rows from a DataFrame based on values in a column in pandas
Random point on a sphere
Are there any space probes or landers which regained communication after being lost?
Writing a worded mathematical expression
What's is this random file in Macintosh HD? Malicious?
Sol Ⅲ = Earth: What is the origin of this planetary naming scheme?
What's the biggest organic molecule that could have a smell?
Exact Brexit date and consequences
What is Japanese Language Stack Exchange called in Japanese?
Are programming languages necessary/useful for operations research practitioner?
Might have gotten a coworker sick, should I address this?
Why did it become so much more expensive to start a university?
How to help my 2.5-year-old daughter take her medicine when she refuses to?
Can a new chain significantly improve the riding experience? If yes - what else can?
Converting multiple assignment statements to single comma separated assignment
Where can I get an anonymous Rav Kav card issued?
Writing a love interest for my hero
Can the UK veto its own extension request?
How to work with a technician hired with a grant who argues everything
Can I say "I have encrypted something" if I hash something?
Is the union of a chain of elementary embeddings elementary?
Is it possible to PIVOT on a LIKE statement
Job offer without any details but asking me to withdraw other applications - is it normal?
Kingdom Map and Travel Pace
Why do sellers care about down payments?
How to replace particular values based on condition by using tf.where()
How can I safely create a nested directory?Does Python have a ternary conditional operator?How to get the current time in PythonHow can I make a time delay in Python?How do I sort a dictionary by value?How to make a flat list out of list of listsHow do I pass a variable by reference?How do I list all files of a directory?How to access environment variable values?Select rows from a DataFrame based on values in a column in pandas
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
I would like to replace values under condition.
NumPy version would go like this
intensity=np.where(
np.abs(intensity)<1e-4,
1e-4,
intensity)
But TensorFlow has a bit different usage for tf.where()
When I tried this
intensity=tf.where(
tf.math.abs(intensity)<1e-4,
1e-4,
intensity)
I got this error
ValueError: Shapes must be equal rank, but are 0 and 4 for 'Select' (op: 'Select') with input shapes: [?,512,512,1], [], [?,512,512,1].
Does that mean I should 4 dimensional tensor for 1e-4
?
python tensorflow
add a comment |
I would like to replace values under condition.
NumPy version would go like this
intensity=np.where(
np.abs(intensity)<1e-4,
1e-4,
intensity)
But TensorFlow has a bit different usage for tf.where()
When I tried this
intensity=tf.where(
tf.math.abs(intensity)<1e-4,
1e-4,
intensity)
I got this error
ValueError: Shapes must be equal rank, but are 0 and 4 for 'Select' (op: 'Select') with input shapes: [?,512,512,1], [], [?,512,512,1].
Does that mean I should 4 dimensional tensor for 1e-4
?
python tensorflow
add a comment |
I would like to replace values under condition.
NumPy version would go like this
intensity=np.where(
np.abs(intensity)<1e-4,
1e-4,
intensity)
But TensorFlow has a bit different usage for tf.where()
When I tried this
intensity=tf.where(
tf.math.abs(intensity)<1e-4,
1e-4,
intensity)
I got this error
ValueError: Shapes must be equal rank, but are 0 and 4 for 'Select' (op: 'Select') with input shapes: [?,512,512,1], [], [?,512,512,1].
Does that mean I should 4 dimensional tensor for 1e-4
?
python tensorflow
I would like to replace values under condition.
NumPy version would go like this
intensity=np.where(
np.abs(intensity)<1e-4,
1e-4,
intensity)
But TensorFlow has a bit different usage for tf.where()
When I tried this
intensity=tf.where(
tf.math.abs(intensity)<1e-4,
1e-4,
intensity)
I got this error
ValueError: Shapes must be equal rank, but are 0 and 4 for 'Select' (op: 'Select') with input shapes: [?,512,512,1], [], [?,512,512,1].
Does that mean I should 4 dimensional tensor for 1e-4
?
python tensorflow
python tensorflow
edited Mar 28 at 11:59
jdehesa
35.3k4 gold badges43 silver badges66 bronze badges
35.3k4 gold badges43 silver badges66 bronze badges
asked Mar 28 at 8:58
YoungMin ParkYoungMin Park
3072 silver badges11 bronze badges
3072 silver badges11 bronze badges
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
Following code passed the error
# Create an array which has small value (1e-4),
# whose shape is (2,512,512,1)
small_val=np.full((2,512,512,1),1e-4).astype("float32")
# Convert numpy array to tf.constant
small_val=tf.constant(small_val)
# Use tf.where()
intensity=tf.where(
tf.math.abs(intensity)<1e-4,
small_val,
intensity)
# Error doesn't occur
print(intensity.shape)
# (2, 512, 512, 1)
You can also directly dosmall_val = tf.full(tf.shape(intensity), tf.constant(1e-4, dtype=intensity.dtype))
, or even justsmall_val = 1e-4 + tf.zeros_(intensity)
.
– jdehesa
Mar 28 at 12:06
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/4.0/"u003ecc by-sa 4.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55393557%2fhow-to-replace-particular-values-based-on-condition-by-using-tf-where%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
Following code passed the error
# Create an array which has small value (1e-4),
# whose shape is (2,512,512,1)
small_val=np.full((2,512,512,1),1e-4).astype("float32")
# Convert numpy array to tf.constant
small_val=tf.constant(small_val)
# Use tf.where()
intensity=tf.where(
tf.math.abs(intensity)<1e-4,
small_val,
intensity)
# Error doesn't occur
print(intensity.shape)
# (2, 512, 512, 1)
You can also directly dosmall_val = tf.full(tf.shape(intensity), tf.constant(1e-4, dtype=intensity.dtype))
, or even justsmall_val = 1e-4 + tf.zeros_(intensity)
.
– jdehesa
Mar 28 at 12:06
add a comment |
Following code passed the error
# Create an array which has small value (1e-4),
# whose shape is (2,512,512,1)
small_val=np.full((2,512,512,1),1e-4).astype("float32")
# Convert numpy array to tf.constant
small_val=tf.constant(small_val)
# Use tf.where()
intensity=tf.where(
tf.math.abs(intensity)<1e-4,
small_val,
intensity)
# Error doesn't occur
print(intensity.shape)
# (2, 512, 512, 1)
You can also directly dosmall_val = tf.full(tf.shape(intensity), tf.constant(1e-4, dtype=intensity.dtype))
, or even justsmall_val = 1e-4 + tf.zeros_(intensity)
.
– jdehesa
Mar 28 at 12:06
add a comment |
Following code passed the error
# Create an array which has small value (1e-4),
# whose shape is (2,512,512,1)
small_val=np.full((2,512,512,1),1e-4).astype("float32")
# Convert numpy array to tf.constant
small_val=tf.constant(small_val)
# Use tf.where()
intensity=tf.where(
tf.math.abs(intensity)<1e-4,
small_val,
intensity)
# Error doesn't occur
print(intensity.shape)
# (2, 512, 512, 1)
Following code passed the error
# Create an array which has small value (1e-4),
# whose shape is (2,512,512,1)
small_val=np.full((2,512,512,1),1e-4).astype("float32")
# Convert numpy array to tf.constant
small_val=tf.constant(small_val)
# Use tf.where()
intensity=tf.where(
tf.math.abs(intensity)<1e-4,
small_val,
intensity)
# Error doesn't occur
print(intensity.shape)
# (2, 512, 512, 1)
edited Mar 28 at 9:22
AkshayNevrekar
6,95312 gold badges23 silver badges45 bronze badges
6,95312 gold badges23 silver badges45 bronze badges
answered Mar 28 at 9:09
YoungMin ParkYoungMin Park
3072 silver badges11 bronze badges
3072 silver badges11 bronze badges
You can also directly dosmall_val = tf.full(tf.shape(intensity), tf.constant(1e-4, dtype=intensity.dtype))
, or even justsmall_val = 1e-4 + tf.zeros_(intensity)
.
– jdehesa
Mar 28 at 12:06
add a comment |
You can also directly dosmall_val = tf.full(tf.shape(intensity), tf.constant(1e-4, dtype=intensity.dtype))
, or even justsmall_val = 1e-4 + tf.zeros_(intensity)
.
– jdehesa
Mar 28 at 12:06
You can also directly do
small_val = tf.full(tf.shape(intensity), tf.constant(1e-4, dtype=intensity.dtype))
, or even just small_val = 1e-4 + tf.zeros_(intensity)
.– jdehesa
Mar 28 at 12:06
You can also directly do
small_val = tf.full(tf.shape(intensity), tf.constant(1e-4, dtype=intensity.dtype))
, or even just small_val = 1e-4 + tf.zeros_(intensity)
.– jdehesa
Mar 28 at 12:06
add a comment |
Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.
Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55393557%2fhow-to-replace-particular-values-based-on-condition-by-using-tf-where%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown