9

I've got an 18x18 2d numpy array (it's a confusion matrix)...and I need/would like to display it as a table in an ipython notebook.

When I simply print it out, it displays with overlap--the rows are so long they take up two lines.

Is there a library that will allow me to print this array in a sort of spreadsheet format?

1
  • you could try to load it into a pandas dataframe. that should look much better. Commented Feb 28, 2016 at 15:39

3 Answers 3

21

You can use Pandas for that.

import pandas as pd
print pd.DataFrame(yourArray)
Sign up to request clarification or add additional context in comments.

Comments

1

A job for matrepr:

from matrepr import mdisplay

mat = np.random.random((18, 18))

mdisplay(mat, floatfmt=".2f", max_rows=18, max_cols=18)

matrepr html output

Comments

-1

Note: Konstantinos proposal holds only for 1-D and 2-D arrays!

You can use numpy.array2string():

from pprint import pprint
import numpy as np

array = np.array([[1,2,3], [4,5,6]])
print(np.array2string(array).replace('[[',' [').replace(']]',']'))

Output:

 [1 2 3]
 [4 5 6]

See also: Printing Lists as Tabular Data

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.