noazet abdo
noazet abdo

Reputation: 113

making zero is zero and finding inverse of matrix in python

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

Answers (1)

thefourtheye
thefourtheye

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

Related Questions