Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

Source Code: Matrix Multiplication Using Nested List Comprehension

# Program to multiply two matrices using list comprehension

# 3x3 matrix
X = [[12,7,3],
    [4 ,5,6],
    [7 ,8,9]]

# 3x4 matrix
Y = [[5,8,1,2],
    [6,7,3,0],
    [4,5,9,1]]

# result is 3x4
result = [[sum(a*b for a,b in zip(X_row,Y_col)) for Y_col in zip(*Y)] for X_row in X]

for r in result:
   print(r)
Comment

PREVIOUS NEXT
Code Example
Python :: update tupple in python 
Python :: pandas write to csv without first line 
Python :: python pandas reading pickelt 
Python :: numpy empty array 
Python :: list python shuffling 
Python :: find python path windows 
Python :: firebase python upload storage 
Python :: jupyter notebook for loop progress bar 
Python :: overlapping date matplotlib 
Python :: python tkinter text widget 
Python :: bs4 find element by id 
Python :: albert pretrained example 
Python :: pearson corr 
Python :: How to efficiently create a median finder for a stream of values, in Python? 
Python :: creating a new folder in python 
Python :: how to write in google chrome console in python 
Python :: import csv file in python 
Python :: how to use Qtimer in thread python 
Python :: write txt python 
Python :: how to stop code in ursina 
Python :: divide a value by all values in a list 
Python :: How to convert a string to a dataframe in Python 
Python :: get number of bits for integer in python 
Python :: pyqt5 qtwebenginewidgets not found 
Python :: pythonic 
Python :: opposite of .isin pandas 
Python :: python tkinter filedialog 
Python :: call materialized view in django postgres 
Python :: py exe tkinter 
Python :: how to add scrollbar to listbox in tkinter 
ADD CONTENT
Topic
Content
Source link
Name
3+1 =