va4.ax.set_title(f'a[:,None,:] * b of shape=(2, 3, 3)') va4.set_colors(va4.get_indices().T, color='lightgreen', basecolor='aqua') va4.vizualize(fixview=True, usetex=False, scale=1.2) va4.ax.dist = 12 ax = fig.add_subplot(2, 3, 5, projection='3d') arr = np.sum((a[:, None, :] * b), axis=2) va5 = VisualArray(arr, fig=fig, ax=ax) va5.ax.set_title(f'np.sum((a[:,None,:] * b), axis=2) \n of shape=(2, 3)') va5.set_colors(va5.get_indices().T, color='lightgreen', basecolor='aqua') va5.vizualize(fixview=True, axis_labels=(None, 'axis=0', 'axis=1'), usetex=False, scale=0.8) va5.ax.dist = 12 ax = fig.add_subplot(2, 3, 6, projection='3d') arr = np.around(np.sum((a[:, None, :] * b), axis=2) / c, 1) va6 = VisualArray(arr, fig=fig, ax=ax) va6.arr = np.array([[[format(n, '.10g') for n in m] for m in o] for o in va6.arr]) va6.ax.set_title(f'np.sum((a[:,None,:] * b), axis=2)/c \n of shape=(2, 3)') va6.set_colors(va6.get_indices().T, color='lightgreen', basecolor='aqua') va6.vizualize(fixview=True, axis_labels=(None, 'axis=0', 'axis=1'), usetex=False, scale=0.7) va6.ax.dist = 12 plt.get_current_fig_manager().window.state('zoomed') plt.show()
arr = np.asarray(arr, dtype='uint32') hexarr = np.vectorize(tohexarr) return hexarr((arr[:, :, 0] << 16) + (arr[:, :, 1] << 8) + arr[:, :, 2]) def tolabels(arr): def tolabelarr(x): return r'\begin{array}{l}\,\,\sharp ' + x[1:4] + r'\\ \,\,\,\, ' + x[ 4:7] + r'\\ ' + r'\\ ' + r'\\ ' + r'\end{array}' labelarr = np.vectorize(tolabelarr) return labelarr(arr) from PIL import Image test_image = Image.open('cat.jpg') test_image = test_image.resize((32, 32), Image.ANTIALIAS) test_image = np.array(test_image).astype(int) arr = tohex(test_image) va = VisualArray(arr) cells = va.get_indices() x, y, z = cells.T va.set_colors(cells.T, color=va.arr[x, y, z]) va.arr = tolabels(va.arr) va.vizualize(fixview=True, scale=0.35, axis_labels=(None, None, None)) va.ax.dist = 11.5 #zoom out a little; change to 3.5 for higher zoom plt.get_current_fig_manager().window.state('zoomed') plt.show()