i am coding for matrix multiplication and addition and i got this error 'TypeError: 'map' object is not subscriptable'. all answers are appreciated :)

Dhanush Gajaraj
print("enter n for nxn matrix:")
n = int(input())

matrix1 = []
matrix2 = []

# elements of first matrix

print("enter elements of first matrix:")
for i in range(0, n):
    # elements of first column

    print("enter elements of {} column".format(i))

    # the elements will be separated by a space
    # input().split() will split the string
    # '1 23 456'.split() will give ['1', '23', '456']
    # map will convert its elements into integers [1, 23, 456]

    matrix1.append(map(int,input().split()))

print("Matrix 1 is {}".format(matrix1))

# taking elements of second matrix

print("enter elements of second matrix")
for i in range(0, n):
    print("enter elements of {} column".format(i))
    matrix2.append(map(int,input().split()))

print("Matrix 2 is {}".format(matrix2))

# addition

addition = []
for i in range(0, n):
    a = []
    for j in range(0, n):
        # making a addition matrix's column to append
        # making a 1D matrix with elements as sum of elements of respective columns of both matrices

        a.append(matrix1[i][j] + matrix2[i][j])
    addition.append(a)
print("Addition of matrix is {}".format(addition))

# multiplication
multiplication = []
for i in range(0, n):
    a = []
    for j in range(0, n):
        b = 0
        for k in range(0, n):
            b = b + (matrix1[i][k] * matrix2[k][j])
        a.append(b)
    multiplication.append(a)
print("Multiplication of matrix is {}".format(multiplication))
Brown Bear

When you use the map function it return you the map object

map(int,"3".split())
<map at 0x7f3550af16d8>

If you want to push the list you should call it for example:

list(map(int,"3".split()))
[3]

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

I got this error in python TypeError: 'NoneType' object is not subscriptable

Why am i getting this error (TypeError: '_io.TextIOWrapper' object is not subscriptable) after the first iteration of my for loop?

TypeError: 'map' object is not subscriptable error in Python 3

Hi, I am new to coding and currently building an MVC and I have a CS0161 ERROR and I cant seem to fix it. Any help appreciated

I can not solve TypeError: 'int' object is not subscriptable

I am trying to apply .apply for a column in pandas but it throws TypeError: 'float' object is not subscriptable

I got the error "TypeError: products.map is not a function"

I have an error in my code the current error is a TypeError: 'NoneType' object is not subscriptable

After recursion I got an Error (TypeError: 'NoneType' object is not iterable)

While trying to get a value of a set I get an error: TypeError: 'method' object is not subscriptable

I encountered an error after running the code: ( sumation = sum(var.copy()) TypeError: 'int' object is not subscriptable)

I'm recieving a TypeError because a NoneType object is not subscriptable. How do I make it subscriptable?

I am getting a Double Multiplication error on this program

How do I solve TypeError: 'set' object is not subscriptable?

"TypeError: ___ object is not subscriptable" in Python and how can I fix it?

TypeError: 'int' object is not subscriptable - I have been looking into this for hours now and i can not understand why it is spitting out this error

when am trying to run this.. i got error..the error is :Cannot read properties of undefined (reading 'map')

I am getting this error message: TypeError: 'function' object is not iterable

I am currently learning about Android services,all the coding part is good,but the manifest gives me the following error

State object.map() returning error - what am I overlooking?

I am trying to improve my run times with Chapel for matrix multiplication

i want to make a toggle div by react spring but i got this error (TypeError: Object(...) is not a function)

I am coding Node struct and I think this is constructor initializer error

Python 3 - TypeError: 'map' object is not subscriptable

error comes as :- 'int' object is not subscriptable when i type latte

Error 'int' object is not subscriptable, How do i convert it to list?

I have an error int object isn't subscriptable

Why am i getting a stack overflow? Advice would be greatly appreciated

i am working on application and i got this notify() error