Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

sparse matrix multiplication in python

def sparse_matrix_multiplication(matrix_a, matrix_b):
    if len(matrix_a[0]) != len(matrix_b):
        return [[]]

    matrix_c = [[0] * len(matrix_b[0]) for _ in range(len(matrix_a))]

    for i in range(len(matrix_c)):
        for j in range(len(matrix_c[0])):
            for k in range(len(matrix_b)):
                if matrix_a[i][k] == 0 or matrix_b[k][j] == 0:
                    continue

                matrix_c[i][j] += matrix_a[i][k] * matrix_b[k][j]

    return matrix_c
Comment

PREVIOUS NEXT
Code Example
Python :: python in line elif 
Python :: Python RegEx Subn – re.subn() 
Python :: sort dataframe by function 
Python :: merge sorting in python 
Python :: django create object from dict 
Python :: tanh activation function 
Python :: download gzip file python 
Python :: all string methods in python 
Python :: f string 
Python :: removing value from list python 
Python :: subarrays in python 
Python :: python 2d matrix declare 
Python :: add to list in python 
Python :: .save() in django 
Python :: python using shutil method 
Python :: python print an array 
Python :: create and add many to many field in django 
Python :: python all 
Python :: python return multiple value from a function 
Python :: help() python 
Python :: signup 
Python :: what are for loops 
Python :: string contains element of list python 
Python :: Patch loop runner _run_once 
Python :: fcn tensorflow 
Python :: python how to extend a class 
Python :: airflow find trigger type 
Python :: pandascheck if two columns match and populate new column 
Python :: index operator in python without input 
Python :: Filter xarray 
ADD CONTENT
Topic
Content
Source link
Name
4+3 =