Challenge: Linear Algebra Foundations #1 – Matrix Addition

Subdomeniu: Linear Algebra Foundations (linear-algebra-foundations)

Scor cont: 2.0 / 2

Submission status: Accepted

Submission score: 1.0

Submission ID: 464716543

Limbaj: python3

Link challenge: https://www.hackerrank.com/challenges/linear-algebra-foundations-1/problem

Cerinta

**Matrix Addition**  

Add the two $3 \times 3$ matrices given below and find the integers corresponding to $a$, $b$, $c$, $d$, $e$, $f$, $g$, $h$, and $i$:

	[1  2  3]       [4  5  6]     [a b c]
	[2  3  4]   +   [7  8  9]  =  [d e f] 
	[1  1  1]       [4  5  7]     [g h i]
 
 
To submit your answer, enter the resultant values of each of the nine integers (i.e., $a$, $b$, $c$, $d$, $e$, $f$, $g$, $h$, and $i$) on a new line and click *Submit Code*.

Input Format

There is no input for this challenge; calculate the values of $a$ through $i$ using the matrices given above.

Output Format

In the text box below, enter the values of each of the nine integers on a new line. You must have a total of nine lines of output and the integers must be printed in order (i.e., $a$, $b$, $c$, $d$, $e$, $f$, $g$, $h$, and $i$, respectively).

Cod sursa

# n_rows=3 #int(input()) # first get number of rows in maxtrix
# n_mats=2 #int(input()) # then get number of matrices

# m_names = ['mtrx_'+str(j) for j in range(0,n_mats)]

# for i in range(0,n_mats):
#     m=[]
#     for r in range(0,n_rows):
#         row = [int(x) for x in input().split()]
#         m.append(row)
#     m_names[i] = m

# # add 2 nxn matrices:
# def add_matrices(m1,m2):
#     return[[m1[j][k]+m2[j][k] for k in range(len(m1))] for j in range(len(m1))]
# my_matrix = add_matrices(m_names[0], m_names[1])

# # print output
# for j in range(len(my_matrix)):
#     for k in range(len(my_matrix)):
#         print(my_matrix[j][k])

my_matrix = [[5,7,9],[9,11,13],[5,6,8]]
# print output
for j in range(len(my_matrix)):
    for k in range(len(my_matrix)):
        print(my_matrix[j][k])
HackerRank Linear Algebra Foundations – Linear Algebra Foundations #1 – Matrix Addition