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

          How to preserve electronics (computers, tablets and phones) for hundreds of years Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern) The network's official Twitter account is up and running again. What content…How might modern humans leave a message for 50,000 years?How would an aquatic race develop computers?How do we make computers care for human life?Keeping supplies for 1000 yearsWhat will cell phones become in 100 years?What body armor protects against a laser?Could a society attain 1800s technology if limited to using copper and bronze?Electricity power (magic) and electronicsScavenging metal resources in post-apocalypse after 100 yearsWhy would precursors create devices that can survive and still work after hundreds of years?

          155 수학 과학 기타 둘러보기 메뉴eh추가해eh문서를 완성해

          Convert JSON to MapSimplest way to convert a string representing JSON array into Java array List of key value pairsHow to take String JSON values into HashMapConvert a JSON String to a HashMapCreating BSON object from JSON stringJSONObject - How to get a value ?Better Map ConstructorReading JSON from Url javaUpdate columns if input values are not null otherwise ignore and keep the existing values of column in databaseHow to store object represented as Json string into Couchbase Lite?Go JSON into MapHow do I efficiently iterate over each entry in a Java Map?Sort a Map<Key, Value> by valuesHow to round a number to n decimal places in JavaCan comments be used in JSON?How do I read / convert an InputStream into a String in Java?How can I pretty-print JSON in a shell script?What is the correct JSON content type?How can I deserialize JSON to a simple Dictionary<string,string> in ASP.NET?Why does Google prepend while(1); to their JSON responses?Parse JSON in JavaScript?