Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9217111
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T02:34:10+00:00 2026-06-18T02:34:10+00:00

I have a Python assignment where I have to transpose a multi-dimensional matrix (3×3,

  • 0

I have a Python assignment where I have to transpose a multi-dimensional matrix (3×3, 4×4,5×5…) without using any for-loops but only using list comprehension.

As an example for a 2×2 matrix, we have:

a2 = [[1, 2], [3, 4]]
n = len(a2)
print [[row[i] for row in a2] for i in range(n)]

But I am not sure I really understand how it works or how to adapt it for a 3×3, 4×4, 5×5… matrix

For instance, with

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

I don’t necessarily want you to give me the answer (still have to figure out by myself), but any hint would be very helpful!

Thanks in advance!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T02:34:11+00:00Added an answer on June 18, 2026 at 2:34 am

    There is a built-in for this – the zip() function.

    >>> list(zip(*[[1, 2], [3, 4]]))
    [(1, 3), (2, 4)]
    

    Note that the call to list() is to show the result, in 3.x, this produces an iterable, not a list (which is lazy, giving memory benefits). In 2.x, it returns a list anyway.

    If you want to transpose the internal parts as well in an example with more nested lists, then it’s relatively simple to use a list comprehension to run zip() on the sublists.

    Example in 2.x for ease of reading:

    >>> zip(*(zip(*part) for part in [[[1, 2], [3, 4]], [[5, 6], [7, 8]]]))
    [((1, 3), (5, 7)), ((2, 4), (6, 8))]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been asked to write a program using python for an assignment. I
As part of the last assignment in a beginner python programing class, I have
This is for a computer science assignment using Python, does anybody know where I
Possible Duplicate: Multiple assignment in Python As we have learnt right since we started
I'm writing a game using Python and PyGame. (This is perscribed in the assignment,
I have a python script that I am writing for a class assignment which
I'm working on an assignment for my CIS class in python. We have to
So I have a Python assignment where I need to use a dictionary to
I have a homework assignment for a Python class and am running into an
I have Python 2.7 running on Windows XP. I am trying to install Spynner

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.