Answered step by step
Verified Expert Solution
Question
1 Approved Answer
python 3, first_divisible def first_divisible(mat, d=2): divisible_indices = [] first_element = mat[0] index = 0 for element in first_element: if(element%d==0 or d%element==0): divisible_indices.append(index) index+=1 if(divisible_indices):
python 3, first_divisible
def first_divisible(mat, d=2):
divisible_indices = []
first_element = mat[0]
index = 0
for element in first_element:
if(element%d==0 or d%element==0):
divisible_indices.append(index)
index+=1
if(divisible_indices):
return divisible_indices
else:
return None
I tried this but it doensn't work. It returns 0. But it should return[0,0]
first divisible: This function takes a nonempty integer numpy matrix and an integer with default value of 2 and returns a list or a 1-D array containing the indices of the first element divisible by the second argument. Your outer loop should go down the rows. If no element is divisible by the integer, return None. For instance, if the matrix is [[1, 2, 9], [7, 11, 13]] and the second argument is 3, the function should return [0, 2]Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started