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;








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?










share|improve this question
































    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?










    share|improve this question




























      0












      0








      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?










      share|improve this question
















      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






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      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

























          1 Answer
          1






          active

          oldest

          votes


















          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)





          share|improve this answer



























          • 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










          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
          );



          );














          draft saved

          draft discarded
















          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









          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)





          share|improve this answer



























          • 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















          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)





          share|improve this answer



























          • 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













          1














          1










          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)





          share|improve this answer















          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)






          share|improve this answer














          share|improve this answer



          share|improve this answer








          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 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
















          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








          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.




















          draft saved

          draft discarded















































          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.




          draft saved


          draft discarded














          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





















































          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







          Popular posts from this blog

          Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

          Swift 4 - func physicsWorld not invoked on collision? The Next CEO of Stack OverflowHow to call Objective-C code from Swift#ifdef replacement in the Swift language@selector() in Swift?#pragma mark in Swift?Swift for loop: for index, element in array?dispatch_after - GCD in Swift?Swift Beta performance: sorting arraysSplit a String into an array in Swift?The use of Swift 3 @objc inference in Swift 4 mode is deprecated?How to optimize UITableViewCell, because my UITableView lags

          Access current req object everywhere in Node.js ExpressWhy are global variables considered bad practice? (node.js)Using req & res across functionsHow do I get the path to the current script with Node.js?What is Node.js' Connect, Express and “middleware”?Node.js w/ express error handling in callbackHow to access the GET parameters after “?” in Express?Modify Node.js req object parametersAccess “app” variable inside of ExpressJS/ConnectJS middleware?Node.js Express app - request objectAngular Http Module considered middleware?Session variables in ExpressJSAdd properties to the req object in expressjs with Typescript