Results 1 to 2 of 2
  1. #1

    Default Python Program to Add Two Matrices

    Hi this is Katy Steven
    I am in 3rd year of engineering, and as my interest is towards learning Python, I have start learning and coding of Python. Now I want to learn how to add two matrix in python. Can anyone suggest me detailed information of this. In short I have require a Python program to add two matrix in Python.

    Hope I will get positive reply from you guys.

    Awaiting for your reply.

  2. #2
    To add two matrices in Python, you can use the following steps:

    1. Define two matrices as nested lists.
    2. Iterate through each row and column of the matrices, adding the corresponding elements and storing the result in a new matrix.
    3. Print the new matrix.

    Here is a short Python program to add two matrices:

    def add_matrices(matrix1, matrix2):
    sum_matrix = []
    for i in range(len(matrix1)):
    row = []
    for j in range(len(matrix1[0])):
    row.append(matrix1[i][j] + matrix2[i][j])
    return sum_matrix

    # Example usage:

    matrix1 = [[1, 2], [3, 4]]
    matrix2 = [[5, 6], [7, 8]]

    sum_matrix = add_matrices(matrix1, matrix2)


    [[6, 8], [10, 12]]
    You can also use the NumPy library to add two matrices in Python development. To do this, you would first need to convert the two matrices to NumPy arrays, and then use the numpy.add() function to add the two matrices.

  3.    Advertisement

Similar Threads

  1. How to add mp3 file to Motorola V3i via USB.. please help
    By jdimpas in forum Gizmos & Gadgets (Old)
    Replies: 8
    Last Post: 01-30-2007, 08:04 PM
  2. HELP: What Program to Cut/Edit MP3s?
    By edgeowns in forum Software & Games (Old)
    Replies: 9
    Last Post: 11-13-2006, 11:20 PM
  3. What Good Programs to Make Invitation Cards?
    By edgeowns in forum Software & Games (Old)
    Replies: 6
    Last Post: 11-01-2006, 08:37 PM
  4. LTFRB computer program to cut red tape
    By grabehbebe in forum Politics & Current Events
    Replies: 4
    Last Post: 06-22-2006, 12:13 PM
  5. how to add pic
    By ruel_d in forum Computer Hardware
    Replies: 1
    Last Post: 12-06-2005, 12:58 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
about us
We are the first Cebu Online Media.

iSTORYA.NET is Cebu's Biggest, Southern Philippines' Most Active, and the Philippines' Strongest Online Community!
follow us