4 deleted 46 characters in body

Ruby, 81787676 62 bytes

->a{i=-1;([a]*a[0].size)1;a[0].flat_map{|a|i+=1;ai+=1;a.map{|b|x=b.map{0};x[i]=b[i];x}}}


sigh Manually keeping track of the index is shorter than with_index.

->a{
i=-1;            # index of the flat_map
([a]*a[0].size)a[0]             # duplicate all rows as many times as necessary
.flat_map {       # we're wrapping each "group" of original rows with yet another
#  array, so we need to flat_map to get rid of those
{|a|             # a is the subarray
i+=1;            # increment the index of the current subarray
a.map{|b|        # for each sub-subarray (these are the rows)...
x=b.map{0};      # zero everything out
x[i]=b[i];       # replace the desired elements
x}}}             # finally, return the modified array


Ruby, 817876 bytes

->a{i=-1;([a]*a[0].size).flat_map{|a|i+=1;a.map{|b|x=b.map{0};x[i]=b[i];x}}}


sigh Manually keeping track of the index is shorter than with_index.

->a{
i=-1;            # index of the flat_map
([a]*a[0].size)  # duplicate all rows as many times as necessary
.flat_map        # we're wrapping each "group" of original rows with yet another
#  array, so we need to flat_map to get rid of those
{|a|             # a is the subarray
i+=1;            # increment the index of the current subarray
a.map{|b|        # for each sub-subarray (these are the rows)...
x=b.map{0};      # zero everything out
x[i]=b[i];       # replace the desired elements
x}}}             # finally, return the modified array


Ruby, 817876 62 bytes

->a{i=-1;a[0].flat_map{i+=1;a.map{|b|x=b.map{0};x[i]=b[i];x}}}


sigh Manually keeping track of the index is shorter than with_index.

->a{
i=-1;            # index of the flat_map
a[0]             # duplicate all rows as many times as necessary
.flat_map{       # we're wrapping each "group" of original rows with yet another
#  array, so we need to flat_map to get rid of those
i+=1;            # increment the index of the current subarray
a.map{|b|        # for each sub-subarray (these are the rows)...
x=b.map{0};      # zero everything out
x[i]=b[i];       # replace the desired elements
x}}}             # finally, return the modified array

3 added 8 characters in body

Ruby, 817878 76 bytes

->a{i=-1;([a]*a[0].size).flat_map{|a|i+=1;a.map{|b|x=[0]*b|b|x=b.size;x[i]=b[i];xmap{0};x[i]=b[i];x}}}


sigh Manually keeping track of the index is shorter than with_index.

->a{
i=-1;            # index of the flat_map
([a]*a[0].size)  # duplicate all rows as many times as necessary
.flat_map        # we're wrapping each "group" of original rows with yet another
#  array, so we need to flat_map to get rid of those
{|a|             # a is the subarray
i+=1;            # increment the index of the current subarray
a.map{|b|        # for each sub-subarray (these are the rows)...
x=[0]*bx=b.size;map{0};      # zero everything out
x[i]=b[i];       # replace the desired elements
x}}}             # finally, return the modified array


Ruby, 8178 bytes

->a{i=-1;([a]*a[0].size).flat_map{|a|i+=1;a.map{|b|x=[0]*b.size;x[i]=b[i];x}}}


sigh Manually keeping track of the index is shorter than with_index.

->a{
i=-1;            # index of the flat_map
([a]*a[0].size)  # duplicate all rows as many times as necessary
.flat_map        # we're wrapping each "group" of original rows with yet another
#  array, so we need to flat_map to get rid of those
{|a|             # a is the subarray
i+=1;            # increment the index of the current subarray
a.map{|b|        # for each sub-subarray (these are the rows)...
x=[0]*b.size;    # zero everything out
x[i]=b[i];       # replace the desired elements
x}}}             # finally, return the modified array


Ruby, 8178 76 bytes

->a{i=-1;([a]*a[0].size).flat_map{|a|i+=1;a.map{|b|x=b.map{0};x[i]=b[i];x}}}


sigh Manually keeping track of the index is shorter than with_index.

->a{
i=-1;            # index of the flat_map
([a]*a[0].size)  # duplicate all rows as many times as necessary
.flat_map        # we're wrapping each "group" of original rows with yet another
#  array, so we need to flat_map to get rid of those
{|a|             # a is the subarray
i+=1;            # increment the index of the current subarray
a.map{|b|        # for each sub-subarray (these are the rows)...
x=b.map{0};      # zero everything out
x[i]=b[i];       # replace the desired elements
x}}}             # finally, return the modified array

2 added 46 characters in body

Ruby, 8181 78 bytes

->a{i=-1;([a]*a[0].size).flat_map.with_index{|a,i|a|a|i+=1;a.map{|b|x=[0]*b.size;x[i]=b[i];x}}}


Room for improvement... especially insidesigh Manually keeping track of the inner mapindex is shorter than with_index.

->a{
i=-1;            # index of the flat_map
([a]*a[0].size)  # duplicate all rows as many times as necessary
.flat_map        # we're wrapping each "group" of original rows with yet another
#  array, so we need to flat_map to get rid of those
.with_index{|a|      # this index will be the index of# thea columnis tothe keepsubarray
{|a,i|i+=1;           # a# isincrement the subarray,index iof isthe itscurrent indexsubarray
a.map{|b|        # for each sub-subarray (these are the rows)...
x=[0]*b.size;    # zero everything out
x[i]=b[i];       # replace the desired elements
x}}}             # finally, return the modified array


Ruby, 81 bytes

->a{([a]*a[0].size).flat_map.with_index{|a,i|a.map{|b|x=[0]*b.size;x[i]=b[i];x}}}


Room for improvement... especially inside the inner map.

->a{
([a]*a[0].size)  # duplicate all rows as many times as necessary
.flat_map        # we're wrapping each "group" of original rows with yet another
#  array, so we need to flat_map to get rid of those
.with_index      # this index will be the index of the column to keep
{|a,i|           # a is the subarray, i is its index
a.map{|b|        # for each sub-subarray (these are the rows)...
x=[0]*b.size;    # zero everything out
x[i]=b[i];       # replace the desired elements
x}}}             # finally, return the modified array


Ruby, 81 78 bytes

->a{i=-1;([a]*a[0].size).flat_map{|a|i+=1;a.map{|b|x=[0]*b.size;x[i]=b[i];x}}}


sigh Manually keeping track of the index is shorter than with_index.

->a{
i=-1;            # index of the flat_map
([a]*a[0].size)  # duplicate all rows as many times as necessary
.flat_map        # we're wrapping each "group" of original rows with yet another
#  array, so we need to flat_map to get rid of those
{|a|             # a is the subarray
i+=1;            # increment the index of the current subarray
a.map{|b|        # for each sub-subarray (these are the rows)...
x=[0]*b.size;    # zero everything out
x[i]=b[i];       # replace the desired elements
x}}}             # finally, return the modified array

1