Skip to content

Write a Python Program to Transpose a Matrix #47

Description

@iamAntimPal

Issue Description

Problem Statement

Create a Python program that takes a matrix (2D list) as input and returns its transpose.

What is Matrix Transposition?

Transposing a matrix means flipping it over its diagonal — the row and column indices of each element are swapped.
For example:

Original Matrix:

1 2 3  
4 5 6

Transposed Matrix:

1 4  
2 5  
3 6

Requirements

  • Prompt the user to input the number of rows and columns.
  • Prompt the user to enter each row's elements.
  • Create the transpose of the matrix.
  • Display the transposed matrix clearly.

Expected Output Example

Enter number of rows: 2  
Enter number of columns: 3  

Enter the elements row by row:  
1 2 3  
4 5 6  

Transpose of the matrix:  
1 4  
2 5  
3 6

Additional Considerations

  • Validate input for proper dimensions and numeric entries.
  • Use nested lists or list comprehensions to perform the transposition.
  • Optional: Offer functionality to perform multiple transpositions in one session.
  • Optional: Use NumPy for a simpler alternative.

Submission Guidelines

  • Fork the repository and create a new branch for this issue.
  • Save the script in basic-python/ or an appropriate directory.
  • Submit a pull request with a descriptive commit message.
  • Optional: Include a README.md explaining the logic and how to run the script.

Acceptance Criteria

  • Correctly generates the transpose of a matrix.
  • Handles invalid or malformed input.
  • Code is clean, beginner-friendly, and well-commented.

Resources

Deadline

Please submit your pull request by 30-04-2025

Metadata

Metadata

Assignees

Labels

enhancementNew feature or requestgood first issueGood for newcomersquestionFurther information is requested

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions