g | x | w | all
Bytes Lang Time Link
015Wolfram Language Mathematica241105T210702Zatt
003Uiua241106T125657Znyxbird
077Scala 3241106T073033Z138 Aspe
006Japt m180103T114217ZShaggy
013Julia 0.6180104T162854Zgggg
030Mathematica180104T024226Ztotallyh
023Wolfram Language Mathematica180104T145151Zalephalp
004J180103T151105ZAdá
021Pari/GP180104T081842Zalephalp
077C gcc180104T015059ZJonathan
058Clean180104T020200ZΟurous
023R180103T123653ZGiuseppe
003APL Dyalog Unicode180103T145453ZAdá
002Jelly180103T133426ZDennis
008CJam180103T132637ZLuis Men
004Husk180103T112000Zბიმო
045Python 2180103T105326ZMr. Xcod
040Haskell180103T115721Ztotallyh
006MATL180103T115448ZSteadybo
007Jelly180103T110154ZMr. Xcod
00705AB1E180103T105537ZEmigna
048JavaScript ES6180103T105319ZArnauld
013Octave180103T105212ZSteadybo

Wolfram Language (Mathematica), 15 bytes

#+Ramp[#-#]&

Try it online!


Wolfram Language (Mathematica), 19 bytes

#~In~#/.In->Max&

Try it online!

In is the most convenient Listable head.

#~In~#           pair elements of matrix and its transpose
      /.In->Max  max each pair

Uiua, 3 bytes

↥⊸⍉

Try it!

↥ maximum ⊸ by ⍉ transpose

Scala 3, 77 bytes

Golfed version. Attempt This Online!

k=>k.zip(k.transpose).map{case(x,y)=>(x zip y).map{case(a,b)=>Math.max(a,b)}}

Ungolfed version. Attempt This Online!

object Main {
  
  def f(k: List[List[Int]]): List[List[Int]] = {
    k.zip(k.transpose).map {
      case (row1, row2) => (row1 zip row2).map { case (a, b) => Math.max(a, b) }
    }
  }

  def main(args: Array[String]): Unit = {
    val tests = List(
      List(List(4, 5, 6), List(1, 7, 2), List(7, 3, 0)),
      List(List(1, 2, 3), List(1, 2, 3), List(1, 2, 3)),
      List(List(4, 5, -6), List(0, 8, -12), List(-2, 2, 4)),
      List(List(172, 29), List(29, 0))
    )
    
    val solutions = List(
      List(List(4, 5, 7), List(5, 7, 3), List(7, 3, 0)),
      List(List(1, 2, 3), List(2, 2, 3), List(3, 3, 3)),
      List(List(4, 5, -2), List(5, 8, 2), List(-2, 2, 4)),
      List(List(172, 29), List(29, 0))
    )

    // First check: print results with explanations
    for ((test, solution) <- tests zip solutions) {
      val result = f(test)
      if (result == solution) {
        println(f"The result is correct: ${result.toString.padTo(36, ' ')}.")
      } else {
        println(f"The result is wrong: ${result.toString.padTo(36, ' ')}.")
      }
    }

    // Second check: assert correctness
    for ((test, solution) <- tests zip solutions) {
      assert(f(test) == solution)
    }

    println("\nAll checks have passed!")
  }
}

Japt -m, 12 10 8 6 bytes

Look, Ma, no transposing or zipping!

ËwWgEV

Try it

Julia 0.6, 13 bytes

max. applies the function max elementwise to it's arugments.

a->max.(a,a')

Try it online!

Mathematica, 30 bytes

-8 bytes thanks to Jonathan Frech.

Map@Max/@t/@t@{#,t@#}&
t=#&

Try it online!

Wolfram Language (Mathematica), 23 bytes

A port of my Pari/GP answer.

(#+#+Abs[#-#])/2&

is \[Transpose].

Try it online!

J, 4 bytes

Tacit prefix function.

>.|:

Try it online!

>. ceiling [of the argument] with

|: the transposed argument

Pari/GP, 21 bytes

m->(m+m~+abs(m-m~))/2

Try it online!

C (gcc), 79 77 bytes

j,i;f(A,n)int*A;{for(j=0;j<n*n;j++)printf("%d,",A[A[j]>A[i=j/n+j%n*n]?j:i]);}

Try it online!

Takes a flat integer array A and the matrix dimension n (as the matrix has to be square) as input. Outputs a flat integer array string representation to stdout.

Clean, 58 bytes

import StdEnv,StdLib
@l=zipWith(zipWith max)(transpose l)l

I don't think this needs an explanation.

Try it online!

R, 23 bytes

function(A)pmax(A,t(A))

Try it online!

This is equivalent to most other answers. However, R has two distinct max functions for the two common scenarios:

max and min return the maximum or minimum of all the values present in their arguments, as integer if all are logical or integer, as double if all are numeric, and character otherwise.

pmax and pmin take one or more vectors (or matrices) as arguments and return a single vector giving the ‘parallel’ maxima (or minima) of the vectors. The first element of the result is the maximum (minimum) of the first elements of all the arguments, the second element of the result is the maximum (minimum) of the second elements of all the arguments and so on. Shorter inputs (of non-zero length) are recycled if necessary.

APL (Dyalog Unicode), 3 bytes

Anonymous tacit prefix function.

⊢⌈⍉

Try it online!

 argument

 ceiling'd with

 transposed argument

Jelly, 2 bytes

»Z

Try it online!

How it works

»Z  Main link. Argument: M (integer matrix)

 Z  Zip the rows of M, transposing rows and columns.
»   Take the maxima of all corresponding integers.

CJam, 8 bytes

{_z..e>}

Anonymous block (function) that takes the input from the stack and replaces it by the output.

Try it online! Or verify all test cases.

Explanation

{      }    e# Define block
 _          e# Duplicate
  z         e# Zip
   .        e# Apply next operator to the two arrays, item by item
            e# (that is, to rows of the two matrices)
    .       e# Apply next operator to the two arrays, item by item
            e# (that is, to numbers of the two rows)
     e>     e# Maximum of two numbers

Husk, 5 4 bytes

Whoop, never got to use before (or ):

S‡▲T

Try it online!

Explanation

S  T -- apply the function to itself and itself transposed
 ‡▲  -- bi-vectorized maximum

Python 2, 45 bytes

lambda k:[map(max,*c)for c in zip(k,zip(*k))]

Try it online!

Thanks to totallyhuman for a few bytes saved.

Haskell, 40 bytes

z(z max)<*>foldr(z(:))e
e=[]:e
z=zipWith

Try it online!

I would ungolf this as:

import Data.List
f m = zipWith (zipWith max) m (transpose m)

...which is so much more elegant.

MATL, 6 bytes

t!2$X>

Try it online!

Explanation:

t        % Duplicate the input.
!        % Transpose the duplicate.
2$X>     % Elementwise maximum of the two matrices.

Jelly, 7 bytes

żZZṀ€$€

Try it online!

05AB1E, 7 bytes

ø‚øεøεà

Try it online!

Explanation

ø         # transpose input matrix
 ‚        # pair with original matrix
  ø       # zip together
   ε      # apply on each sublist ([[row],[transposed row]])
    ø     # zip
     ε    # apply on each sublist (pair of elements)
      à   # extract greatest element

JavaScript (ES6), 48 bytes

m=>m.map((r,y)=>r.map((v,x)=>v>(k=m[x][y])?v:k))

Test cases

let f =

m=>m.map((r,y)=>r.map((v,x)=>v>(k=m[x][y])?v:k))

console.log(JSON.stringify(f([[172,29],[29,0]]            ))) // -> [[172,29],[29,0]]
console.log(JSON.stringify(f([[4,5,6],[1,7,2],[7,3,0]]    ))) // -> [[4,5,7],[5,7,3],[7,3,0]]
console.log(JSON.stringify(f([[1,2,3],[1,2,3],[1,2,3]]    ))) // -> [[1,2,3],[2,2,3],[3,3,3]]
console.log(JSON.stringify(f([[4,5,-6],[0,8,-12],[-2,2,4]]))) // -> [[4,5,-2],[5,8,2],[-2,2,4]]

Octave, 13 bytes

@(A)max(A,A')

Try it online!