0

How can I print matrix nicely with headers like this:

      T  C  G  C  A
  [0 -2 -4 -6 -8 -10]
T [-2  1 -1 -3 -5 -7]
C [-4 -1  2  0 -2 -4]
C [-6 -3  0  1  1 -1]
A [-8 -5 -2 -1  0  2]

I have tried to print with numpy.matrix(mat), But all I have got was:

[[  0  -2  -4  -6  -8 -10]
 [ -2   1  -1  -3  -5  -7]
 [ -4  -1   2   0  -2  -4]
 [ -6  -3   0   1   1  -1]
 [ -8  -5  -2  -1   0   2]]

And I also didn't succeed to add the headers.

Thanks!

1 Answer 1

1

You can use the pandas library for that:

>>> from pandas import DataFrame
>>> matrix = [(' ', [  0, -2, -4, -6, -8, -10]),
...  ('T', [ -2,  1, -1, -3, -5, -7]),
...  ('G', [ -4, -1,  2,  0, -2, -4]),
...  ('C', [ -6, -3,  0,  1,  1, -1]),
...  ('A', [ -8, -5, -2, -1,  0,  2])]
...
>>> DataFrame.from_items(matrix, orient = 'index', columns = [' ', 'T', 'G', 'C', 'A'])
      T  G  C  A
   0 -2 -4 -6 -8
T -2  1 -1 -3 -5
G -4 -1  2  0 -2
C -6 -3  0  1  1
A -8 -5 -2 -1  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.