@@ -87,6 +87,16 @@ def subtraction(matrix_1: matrix, matrix_2: matrix) -> matrix:
87
87
difference_m [i ][j ] = matrix_1 [i ][j ] - matrix_2 [i ][j ]
88
88
return difference_m
89
89
90
+ # noinspection PyUnusedLocal
91
+ @staticmethod
92
+ def scalar_multiplication (matrix_1 : matrix , scalar : float ) -> matrix :
93
+ dim : dimensions = MatrixOperations .get_dimensions (matrix_1 )
94
+ product_m : matrix = [[0 for cols in range (dim [1 ])] for rows in range (dim [0 ])]
95
+ for i in range (0 , dim [0 ]):
96
+ for j in range (0 , dim [1 ]):
97
+ product_m [i ][j ] = matrix_1 [i ][j ] * scalar
98
+ return product_m
99
+
90
100
# noinspection PyUnusedLocal
91
101
@staticmethod
92
102
def multiplication (matrix_1 : matrix , matrix_2 : matrix ) -> matrix :
@@ -126,6 +136,7 @@ def display(matrix_1: matrix) -> None:
126
136
m_2 = [[10 , 20 , 30 ], [40 , 5 , 6 ], [7 , 8 , 9 ]]
127
137
m_3 = [[1 , 2 , 3 ], [4 , 5 , 6 ], [7 , 8 , 9 ]]
128
138
m_4 = [[1 , 2 ], [4 , 5 ], [7 , 8 ]]
139
+ scalar_value = 0.5
129
140
130
141
addition = MatrixOperations .addition (m_1 , m_2 )
131
142
difference = MatrixOperations .subtraction (m_1 , m_2 )
@@ -147,5 +158,7 @@ def display(matrix_1: matrix) -> None:
147
158
MatrixOperations .display (difference )
148
159
print ('Multiplication of Matrix 3 & 4:' )
149
160
MatrixOperations .display (product )
161
+ print (f'Scalar Multiplication of Matrix 1 by { scalar_value } :' )
162
+ MatrixOperations .display (MatrixOperations .scalar_multiplication (m_1 , scalar_value ))
150
163
print ('Identity Matrix:' )
151
164
MatrixOperations .display (MatrixOperations .identity (3 ))
0 commit comments