Matrix operations using map() Dry Run in PYTHON

Matrix operations using map() is an interactive PYTHON dry run visualizer from the Special programs section. Study the source code, then use the execution controls to follow each step, variable update, highlighted line, and console output.

This page provides a browser-based dry run with source-code highlighting, auto-scroll, voice narration controls, and execution output for learning the program step by step.

Matrix operations using map() Program Code

# Matrix addition using map
matrix_a = [[1, 2, 3], [4, 5, 6], [7, 8, 9]]
matrix_b = [[9, 8, 7], [6, 5, 4], [3, 2, 1]]

# Add two matrices
matrix_sum = list(map(
    lambda row_pair: list(map(lambda x: x[0] + x[1], zip(row_pair[0], row_pair[1]))),
    zip(matrix_a, matrix_b)
))

# Scalar multiplication
scalar = 3
matrix_scaled = list(map(
    lambda row: list(map(lambda x: x * scalar, row)),
    matrix_a
))

# Transpose using zip and map
matrix_transpose = list(map(list, zip(*matrix_a)))

print("Matrix A:", matrix_a)
print("Matrix B:", matrix_b)
print("A + B:", matrix_sum)
print(f"A × {scalar}:", matrix_scaled)
print("Transpose of A:", matrix_transpose)

View the complete Special programs page.

Program Console Matrix operations using map() Topic: PYTHON Vignaankosh.com
Execution Panel
Step 0/0
Console is empty.