The Numpythonic approach: (using numpy.dot in order to get the dot product of two matrices)

In [1]: import numpy as np

In [3]: np.dot([1,0,0,1,0,0], [[0,1],[1,1],[1,0],[1,0],[1,1],[0,1]])
Out[3]: array([1, 1])

The Pythonic approach:

The length of your second for loop is len(v) and you attempt to indexing v based on that so you got index Error . As a more pythonic way you can use zip function to get the columns of a list then use starmap and mul within a list comprehension:

In [13]: first,second=[1,0,0,1,0,0], [[0,1],[1,1],[1,0],[1,0],[1,1],[0,1]]

In [14]: from itertools import starmap

In [15]: from operator import mul

In [16]: [sum(starmap(mul, zip(first, col))) for col in zip(*second)]
Out[16]: [1, 1]
Answer from Kasravnd on Stack Overflow
๐ŸŒ
OpenGenus
iq.opengenus.org โ€บ matrix-multiplication-in-python
Matrix Multiplication in Python (with and without Numpy)
April 11, 2023 - In Python, this operation can be performed using the ... dot for matrix multiplication. The rule for matrix multiplication is that two matrices can only be multiplied if the number of columns in the first matrix is the same as the number of rows in the second matrix.
Discussions

Matrix multiplication in pythonwithout numpy
# write your python code here # you can take the above example as sample input for your program to test # it should work for any general input try not to hard code for only given input examples # you can feel free to change all these codes/structure # here A and B are list of lists import numpy ... More on forum.freecodecamp.org
๐ŸŒ forum.freecodecamp.org
7
0
September 20, 2020
matrix - Matrices multiplication in python without using numpy - Stack Overflow
I've been trying to get this method ready for matrices multiplication. I'm using the __mul__ special function for it. This is the code i got so far: def verify_mul(self, other): # only multiply when More on stackoverflow.com
๐ŸŒ stackoverflow.com
python - Multiplying matrixes without Numpy - Stack Overflow
I want to write a code which will multiply matrixes without using Numpy in Python. Unfortunately written function gives wrong result. Have an idea what is incorrect? A = [[1, 2, 3], [4, 5, 6]]... More on stackoverflow.com
๐ŸŒ stackoverflow.com
March 1, 2021
python - matrix multiplication without numpy - Stack Overflow
Communities for your favorite technologies. Explore all Collectives ยท Stack Overflow for Teams is now called Stack Internal. Bring the best of human thought and AI automation together at your work More on stackoverflow.com
๐ŸŒ stackoverflow.com
๐ŸŒ
Medium
medium.com โ€บ @vtalladin06 โ€บ matrix-multiplication-in-python-without-libraries-a83b68819477
Matrix Multiplication in Python without libraries | by Tahseen Alladin | Medium
December 25, 2023 - Implementing matrix multiplication without external libraries can be a useful exercise that allows you to understand the fundamental principles behind matrix operations and algorithms.
๐ŸŒ
Learn Coding Fast
learncodingfast.com โ€บ home โ€บ python programming challenge 2: multiplying matrices without numpy
Python Programming Challenge 2: Multiplying Matrices without numpy | Learn Coding Fast
August 30, 2020 - For instance, the diagram below shows how we get the number 38 by multiplying the first row (2, 3, 6) in the first matrix with the first column (1, 2, 5) in the second matrix. Clear? If you are lost, you can refer to the YouTube video below for a more detailed explanation: For those of you who are familiar with using Python for data science, you have probably used the numpy module to multiply matrices before.
๐ŸŒ
freeCodeCamp
forum.freecodecamp.org โ€บ curriculum help
Matrix multiplication in pythonwithout numpy - Curriculum Help - The freeCodeCamp Forum
September 20, 2020 - # write your python code here # you can take the above example as sample input for your program to test # it should work for any general input try not to hard code for only given input examples # you can feel free to change all these codes/structure # here A and B are list of lists import numpy as np def matrix_mul(): a=[] ac=0 ace=0 bc=0 bce=0 result=[] A = [[1,3,4], [2,5,7], [5,9,6]] B = [[1,0,0], [0,1,0...
๐ŸŒ
Stack Overflow
stackoverflow.com โ€บ questions โ€บ 71168359 โ€บ matrices-multiplication-in-python-without-using-numpy
matrix - Matrices multiplication in python without using numpy - Stack Overflow
I've been trying to get this method ready for matrices multiplication. I'm using the __mul__ special function for it. This is the code i got so far: def verify_mul(self, other): # only multiply when
Find elsewhere
๐ŸŒ
Stack Overflow
stackoverflow.com โ€บ questions โ€บ 66427420 โ€บ multiplying-matrixes-without-numpy
python - Multiplying matrixes without Numpy - Stack Overflow
March 1, 2021 - A = [[1, 2, 3], [4, 5, 6]] B = [[1, 2], [3, 4], [5, 6]] def MatrixMultiply(A, B): result = [] for m in range(0, len(A) - 1): rows = [] for i in range(0, len(B[0]) - 1): columns = 0 for j in range (0, len(A)): columns += A[m][j] * B[j][i] rows.append(columns) result.append(rows) return result print(MatrixMultiply(A, B)) ...
๐ŸŒ
Towards Data Science
towardsdatascience.com โ€บ home โ€บ latest โ€บ python coding from scratch: matrix multiplication without any machine learning libraries!
Python Coding From Scratch: Matrix Multiplication Without Any Machine Learning Libraries! | Towards Data Science
March 5, 2025 - The first step, before doing any matrix multiplication is to check if this operation between the two matrices is actually possible. This can be done by checking if the columns of the first matrix matches the shape of the rows in the second matrix.
๐ŸŒ
Reddit
reddit.com โ€บ r/learnprogramming โ€บ multiplying matrices without numpy[python]
r/learnprogramming on Reddit: Multiplying Matrices without Numpy[Python]
February 25, 2017 -

I am trying to multiply matrices for an assignment but our professor just informed us (a day before it is due) that we can't import numpy for our program. How would I get started with this? Would I have it look through the values in the list? Thanks

Here is the exact question being asked:

Write the procedure that computes the multiplication of two matrices. Your code should work for any size matrices, assuming that the total number of columns in the first matrix matches the total number ofrows in the second matrix.

๐ŸŒ
Reddit
reddit.com โ€บ r/learnpython โ€บ help with matrices (without using numpy)
r/learnpython on Reddit: Help with matrices (without using numpy)
February 19, 2021 -

Hello,

I'm learning to code in Python and I'm stuck on a part of a question. I have googled a lot and tried to do it without success.

The user enters two matrices that are retained in the program as two-dimensional lists. The program checks whether the matrix sizes allow matrix multiplication and in that case performs the matrix multiplication. The result is saved in a new two-dimensional list.

I succeed with the part where users input the lists, but do not know how to proceed after that. Does anyone have any ideas on how to do this? I'm not allowed to use numpy on this assignment.

I would really appreciate some help.

๐ŸŒ
Blogger
edspi31415.blogspot.com โ€บ 2022 โ€บ 10 โ€บ matrices-in-python-without-numpy-part-2.html
Eddie's Math and Calculator Blog: Matrices in Python without Numpy: Part 2
October 4, 2022 - Matrix multiplication is not communitive. Hence, mat1 * mat2 โ‰  mat2 * mat1 ... Note that both madd and mmult require newmatrix. See yesterday's post for the code for newmatrix. Next time, we will work with determinants and inverses. ... Ives, Thom. "BASIC Linear Algebra Tools in Pure Python without Numpy or Scipy" Integrated Machine Learning & AI December 11, 2018.
๐ŸŒ
Programiz
programiz.com โ€บ python-programming โ€บ examples โ€บ multiply-matrix
Python Program to Multiply Two Matrices | Programiz
March 14, 2024 - Multiplication of two matrices X and Y is defined only if the number of columns in X is equal to the number of rows Y. If X is a n x m matrix and Y is a m x l matrix then, XY is defined and has the dimension n x l (but YX is not defined).
๐ŸŒ
Stack Overflow
stackoverflow.com โ€บ questions โ€บ 57325193 โ€บ matrix-multiplication-in-python-without-numpy
Matrix multiplication in Python without Numpy - Stack Overflow
August 2, 2019 - In fact Python doesn't have any built-in matrix type, so matrix multiplication doesn't make much sense here. But of course you're free to implement your own :-) By the way Ellipsis is also mostly used by Numpy (though it found its application ...
๐ŸŒ
Scaler
scaler.com โ€บ home โ€บ topics โ€บ python program to multiply two matrices
Python Program to Multiply Two Matrices - Scaler Topics
February 23, 2024 - This method encodes two matrices, A and B, as nested lists in Python and retrieves their dimensions. It then checks for compatibility and initializes a product matrix C with zeros. Matrix multiplication is performed using nested loops, computing each element of C as the sum of products of ...
๐ŸŒ
freeCodeCamp
forum.freecodecamp.org โ€บ curriculum help
Python arrays without numpy! - Curriculum Help - The freeCodeCamp Forum
November 5, 2020 - Can someone help me regarding the subtraction and multiplication of two matrices which I created using arrays (without numpy) and I am doing it using object oriented by making class and functions. I had created 2 matrices and print them by calling the class in objects and now I have to make a function in the same class which subtracts and another function which multiplies these 2 matrices.
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ python โ€บ python-program-multiply-two-matrices
Python Program to Multiply Two Matrices - GeeksforGeeks
This method uses the classic three-loop approach: the outer loop picks a row from A, the middle loop picks a column from B, and the inner loop multiplies corresponding elements and adds them up.
Published: November 27, 2025
๐ŸŒ
Roadmap
roadmap.sh โ€บ python-data-analysis โ€บ matrix-multiplication
Matrix Multiplication in Python: The Complete Decision Guide
September 22, 2026 - Switching * and @ commonly leads to silent errors in Python programs when both operations are valid, so be sure to use @ for matrix multiplication and save * for elementwise or scalar multiplication. As a final consideration, NumPy can operate on arrays with different but compatible dimensions using a technique called broadcasting. This allows calculations between smaller and larger arrays without the need for copying or reshaping the data.
๐ŸŒ
YouTube
youtube.com โ€บ watch
Matrix multiplication from scratch in Python | No NumPy, no libraries | Coding for ML [Lecture 29] - YouTube
Colab link: https://colab.research.google.com/drive/1PJkxrKekiVNe-SdMaGMoQMqU6ZC4Evv-?usp=sharingI am excited to share my newest lecture on implementing matr
Published: March 13, 2025