#!/usr/bin/env python # coding: utf-8 # # MatRepr PyData/Sparse # # Demonstrate: # * 2D matrix # * 1D vector # * multidimensional # # With rendering: # * native pydata/sparse # * with MatRepr Jupyter integration, both default and a more compact size # * MatRepr LaTeX output # * MatRepr string output # In[1]: import sparse # so matrepr can be imported from the source tree. import sys sys.path.insert(0, '..') from matrepr import mdisplay # In[2]: import numpy numpy.random.seed(1234) A = sparse.random((100, 100), density=0.21234) # v = sparse.COO([0, 1, 2, 3, 99], data=[1000, 1001, 1002, 1003, 1099], shape=(100,)) v = sparse.random((1000,), density=0.5) # T = sparse.COO(coords=[[0, 1], [3, 2], [1, 3]], data=[111, 222], shape=(5, 5, 5)) T = sparse.random((1000, 100, 100), density=0.21234) # ## PyData/Sparse native formatting # In[3]: A # In[4]: v # In[5]: T # ## MatRepr default # In[6]: get_ipython().run_line_magic('load_ext', 'matrepr') # In[7]: A # In[8]: v # In[9]: T # ## LaTeX # In[10]: mdisplay(A, "latex") # In[11]: mdisplay(v, "latex") # In[12]: mdisplay(T, "latex") # ## String # In[13]: mdisplay(A, "str") # In[14]: mdisplay(v, "str") # In[15]: mdisplay(v, "str", indices=False, title=False) # In[16]: mdisplay(T, "str") # ## More compact size # In[17]: import matrepr matrepr.params.max_rows = 10 matrepr.params.max_cols = 7 matrepr.params.num_after_dots = 0 matrepr.params.indices = False # In[18]: A # In[19]: v # In[20]: T # In[20]: