Reputation: 113
guys i am totally new to programming ... i want to make a function that takes a matrix and maps each nonzero element to its inverse and zero to zero in python... so here is my code
def question_1_c(arr):
new_arr = []
for i in range(len(arr)):
row_arr = []
for j in range(len(arr[i])):
if (arr[i][j]!==0) :
row_arr.append(1/ arr[i][j])
new_arr.append(row_arr)
else:
row_arr.append(0)
new_arr.append(row_arr)
return new_arr
question_1_c(Matrix(L, [[70,52,13,67],[90,48,57,26],[43,45,67,89],[88,65,44,23]]))
but an invalid syntax appeared any help please
Upvotes: 1
Views: 103
Reputation: 239683
if (arr[i][j] !== 0) :
This should have been
if (arr[i][j] != 0) :
!==
is a valid comparison operator in javascript not in python.
Upvotes: 1