VizArray

The VizArray package provides a simple way of visualizing 2d NumPy arrays using the ipythonblocks library. The goal of VizArray is to help teach array based programming.

Importing


In [1]:
%matplotlib inline
import numpy as np
import vizarray

Manual usage

To visualize a NumPy array, just pass it to the vizarray.vizarray function:


In [2]:
a = np.random.rand(10,10)

In [3]:
vizarray.vizarray(a)


Out[3]:

Automatic usage

If you call enable_notebook, vizarray will automatically be used as the default display method for all NumPy arrays:


In [4]:
vizarray.enable_notebook()

In [5]:
a


Out[5]:

Basic API

Slicing works as expected:


In [6]:
a[0:2,0:2]


Out[6]:

In [7]:
a[0,:]


Out[7]:

In [8]:
a[:,0:2]


Out[8]:

You can set the colormap that is used with the set_cmap function, which accepts Matplotlib colormap names:


In [9]:
vizarray.set_cmap('Blues')

In [10]:
a


Out[10]:

In [11]:
t = np.linspace(0,2.0*np.pi,100)

In [12]:
t


Out[12]:

In [13]:
np.sin(t)


Out[13]:

You can set the block size in pixels (default is 30):


In [14]:
vizarray.set_block_size(10)

In [15]:
a


Out[15]:

The disable function will return NumPy arrays to their usual display format:


In [16]:
vizarray.disable_notebook()

In [17]:
a


Out[17]:
array([[ 0.40757099,  0.1817572 ,  0.64854632,  0.5665256 ,  0.21797424,
         0.88198307,  0.59328478,  0.14814611,  0.66887321,  0.50148364],
       [ 0.26050509,  0.50097652,  0.52283948,  0.09928335,  0.1372609 ,
         0.23969422,  0.89080929,  0.84870735,  0.67918145,  0.8803606 ],
       [ 0.52377011,  0.78982269,  0.03789964,  0.91032241,  0.32918112,
         0.600385  ,  0.41836973,  0.18588686,  0.81316566,  0.36657394],
       [ 0.68637939,  0.36921532,  0.76837074,  0.20041975,  0.09615646,
         0.44048807,  0.21225954,  0.67801696,  0.29816408,  0.59711574],
       [ 0.14779768,  0.06047233,  0.52872618,  0.07807344,  0.22471503,
         0.62748135,  0.3923704 ,  0.86212821,  0.36525458,  0.62610908],
       [ 0.03541459,  0.43252417,  0.62418026,  0.37498822,  0.38618418,
         0.5909517 ,  0.63998954,  0.91340551,  0.28396807,  0.18277296],
       [ 0.55384486,  0.23391519,  0.90874104,  0.7739711 ,  0.40598224,
         0.52132742,  0.84132396,  0.18862276,  0.61303793,  0.48451052],
       [ 0.06922383,  0.52104436,  0.25186819,  0.31214033,  0.48581611,
         0.0841071 ,  0.02663194,  0.73357068,  0.11383662,  0.78410077],
       [ 0.75222785,  0.76106838,  0.63603274,  0.69088666,  0.07417917,
         0.07010039,  0.89988162,  0.3806107 ,  0.62126808,  0.86166343],
       [ 0.70951191,  0.65486779,  0.91869925,  0.57354937,  0.00949937,
         0.89237004,  0.48462266,  0.01408788,  0.2768876 ,  0.06766195]])