title: Max value on 2D array and make the rest zero based on a condition
body: <p>I use this to select the max value in place of a row in a 2D numpy and make the rest of the values zero</p>
  <pre><code>max_row_value_2D = a * (a &gt;= np.sort(a, axis=1)[:, [-1]]).astype(int)
  </code></pre>
  <p>I use this to select the max value in place of a column in a 2D numpy and make the rest of the values zero</p>
  <pre><code>max_column_value_2D = a * (a &gt;= np.sort(a, axis=0)[[-1], :]).astype(int)
  </code></pre>
  <p>I would like to create a new 2D array based on the following condition. 1) Select the max value in place of a row in a 2D numpy and make the rest of the values zero (code above) 2) If a column has no value, then select the max value in the corresponding column in place, and make the rest zero (they will already be zero since the row condition has zeroed them).</p>
  <p>Examples:</p>
  <pre><code>input:
  [[2 , 2 ,3 ],
  [1 , 3 ,4 ],
  [0, 4, 5]]
  
  output:
  [[0,0,3],
  [0,0,4],
  [0,4,5]]
  </code></pre>
  <p>In the above example, the max value of each row has been selected, however columns 1 and 2 are empty. How can I modify the code to then further select the max values in place for the column if the column does not have a value in any of the rows? This way each column and row will have a value. Therefore, some rows will have 1+ values, and some columns will have 1+ values.</p>
  <p>Desired output:</p>
  <pre><code>[[2,0,3],
  [0,0,4],
  [0,4,5]]
  </code></pre>
  <p>Every row has atleast one max value, every column has atleast one max value. If the row happens to have more than 1 value, then it is the max value of the column.</p>