1

How do you transpose a matrix without using numpy or zip or other imports?

I thought this was the answer but it does not work if the matrix has only 1 row...

[[row[i] for row in data] for i in range(len(data[1]))]

3
  • do you mean one row like m=[1,2,3] or m=[[1,2,3]] ? Commented Feb 27, 2014 at 20:48
  • 2
    [1] should be [0] .... [[row[i] for row in data] for i in range(len(data[0]))] Commented Feb 27, 2014 at 20:49
  • cmd you are totally right, thanks for catching that it was driving me nuts Commented Feb 27, 2014 at 20:58

1 Answer 1

6

[[row[i] for row in data] for i in range(len(data[0]))]

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.