Skip to main content
add solution
Source Link
AsukaMinato
  • 10.4k
  • 1
  • 17
  • 44

Transpose and then Map

{{2, 1, 1}, {0, 1, 0}, {0, 0, 1}} // Transpose // 
 Map[If[MemberQ[#, 1] || MemberQ[#, -1], x, y] &]

Or

{{2, 1, 1}, {0, 1, 0}, {0, 0, 1}} // Transpose // 
 Map[If[ContainsAny[#, {1, -1}], x, y] &]
{y, x, x}

Transpose and then Map

{{2, 1, 1}, {0, 1, 0}, {0, 0, 1}} // Transpose // 
 Map[If[MemberQ[#, 1], x, y] &]
{y, x, x}

Transpose and then Map

{{2, 1, 1}, {0, 1, 0}, {0, 0, 1}} // Transpose // 
 Map[If[MemberQ[#, 1] || MemberQ[#, -1], x, y] &]

Or

{{2, 1, 1}, {0, 1, 0}, {0, 0, 1}} // Transpose // 
 Map[If[ContainsAny[#, {1, -1}], x, y] &]
{y, x, x}
Source Link
AsukaMinato
  • 10.4k
  • 1
  • 17
  • 44

Transpose and then Map

{{2, 1, 1}, {0, 1, 0}, {0, 0, 1}} // Transpose // 
 Map[If[MemberQ[#, 1], x, y] &]
{y, x, x}