Zeroing A Matrix
February 17, 2017
Today’s exercise is a simple interview question from ADP:
Given a two-dimensional matrix of integers, for any cell that initially contains a zero, change all elements of that cell’s row and column to zero.
Your task is to write the indicated program. When you are finished, you are welcome to read or run a suggested solution, or to post your own solution or discuss the exercise in the comments below.
In Python using numpy.
import numpy as np def zero(matrix): rows, cols = [list(set(x)) for x in np.where(matrix == 0)] matrix[rows, :] = 0 matrix[:, cols] = 0A solution in Racket.