Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,936 questions

51,873 answers

573 users

How to multiply two 2D lists in Python

3 Answers

0 votes
import numpy as np

list1 = [[1, 2, 3], [4, 5, 6]]
list2 = [[9, 0, 5], [8, 7, 1]] 

multiply = np.multiply(list1,list2)

print(multiply)



'''
run:

[[ 9  0 15]
 [32 35  6]]

'''

 



answered Apr 18, 2021 by avibootz
0 votes
list1 = [[1, 2, 3], [4, 5, 6]]
list2 = [[9, 0, 5], [8, 7, 1]] 

multiply = [[0] * 3] * 2 

for i in range(len(list1)):
    multiply[i] = [x * y for x, y in zip(list1[i], list2[i])]

print(multiply)




'''
run:

[[9, 0, 15], [32, 35, 6]] 

'''

 



answered Apr 18, 2021 by avibootz
0 votes
list1 = [[1, 2, 3], [4, 5, 6]]
list2 = [[9, 0, 5], [8, 7, 1]] 

multiply = [[0] * 3] * 2 

for i in range(len(list1)):
    multiply[i] = list(map(lambda x, y: x * y ,list1[i], list2[i]))

print(multiply)




'''
run:

[[9, 0, 15], [32, 35, 6]] 

'''

 



answered Apr 18, 2021 by avibootz

Related questions

3 answers 269 views
269 views asked Apr 18, 2021 by avibootz
1 answer 195 views
1 answer 207 views
2 answers 133 views
1 answer 127 views
127 views asked Feb 27, 2019 by avibootz
...