Visualization#

The visualization module provides a way to visualize tensors.

Installation#

Since this module is optional, we need to install it before using it:

pip install ninetoothed[visualization]

Visualizing a Tensor#

visualize is the primary function of this module:

ninetoothed.visualization.visualize(tensor, color=None, save_path=None)#

Visualize a tensor as a structured grid representation.

Parameters:
  • tensor – The tensor to be visualized.

  • color – The color to be used for visualization.

  • save_path – The path where the visualization should be saved.

Basic Usage#

If we just want to temporarily visualize a tensor, the simplest way is to pass the tensor to visualize and provide a save path. Then, visualize will save the generated image at the specified location.

x = Tensor(shape=(4, 8))
visualize(x, save_path="x.png")

This method can also be used to temporarily visualize multiple tensors. You just need to pass the corresponding tensors and save paths to visualize.

x = Tensor(shape=(4, 8))
visualize(x, save_path="x.png")

y = Tensor(shape=(8, 4))
visualize(y, save_path="y.png")

z = Tensor(shape=(4, 4))
visualize(z, save_path="z.png")

Specifying Colors#

When using the above method, tensors are assigned default colors. To customize colors, we can use the color parameter, following Matplotlib’s color formats.

x = Tensor(shape=(4, 8))
visualize(x, color="orange", save_path="x.png")