Reputation: 5329
Is there a quick way (without the overhead of using a GUI or graphics module) to visually render 2d and 3d lists.
For example if I have a 2d array of zeros and ones, I would like to draw a black and white grid according to this array.
I am looking for a module that allows me to do these thing in simple ways. Similar to the easiness of that matplotlib allows drawing graphs.
Upvotes: 6
Views: 487
Reputation: 43061
Are you looking for something to run on command line? If that is so, you could simply write your own little function in a very few lines. Something like this:
>>> matrix = [[0,1,0],[1,1,1],[0,0,1]]
>>> convert = lambda x : '■ ' if x == 1 else '□ '
>>> for row in matrix:
... print ''.join([convert(el) for el in row])
...
□ ■ □
■ ■ ■
□ □ ■
Upvotes: 3
Reputation: 4928
The command matshow in matplotlib displays a matrix:
import pylab as p
p.matshow(p.array([[0,1],[1,1]]),cmap="Greys") ; p.show()
This would work for 2d lists. As for 3d lists, I'm not sure I fully understand how you're planning on visualising them.
Upvotes: 7