Example #1
0
                [[r'$x^4y$', r'$x^3y^2$'], [r'$x^3y^2$', r'$x^2y^3$']],
                [[r'$x^3y^2$', r'$x^2y^3$'], [r'$x^2y^3$', r'$xy^4$']],
                [[r'$x^4y$', r'$x^3y^2$'], [r'$x^3y^2$', r'$x^2y^3$']],
                [[r'$x^3y^2$', r'$x^2y^3$'], [r'$x^2y^3$', r'$xy^4$']],
                [[r'$x^5$', r'$x^4y$'], [r'$x^4y$', r'$x^3y^2$']],
                [[r'$x^4y$', r'$x^3y^2$'], [r'$x^3y^2$', r'$x^2y^3$']]])

ax = fig.add_subplot(1, 2, 1, projection='3d')
va = VisualArray(arr, fig=fig, ax=ax)
va.set_colors(np.where(arr == '$x^5$'), color='#6666ff')
va.set_colors(np.where(arr == '$x^4y$'), color='#66ff66')
va.set_colors(np.where(arr == '$x^3y^2$'), color='#ff6666')
va.set_colors(np.where(arr == '$x^2y^3$'), color='#ffff66')
va.set_colors(np.where(arr == '$xy^4$'), color='#ff66ff')
va.set_colors(np.where(arr == '$y^5$'), color='#66ffff')
va.permute(shape=(2, 2, 2, 2, 2))
va.vizualize(
    fixview=True,
    axis_labels=[
        r'$\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!' + 'x(x+y)\!\!+\!\!y(x+y)$',
        r'$\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!' + 'x(x+y)\!\!+\!\!y(x+y)$',
        r'$\!\!x+y$'
    ],
    scale=0.6)
va.ax.set_title(
    r'Why $(x+y)^5 = x^5+5x^4y+10x^3y^2+10x^2y^3+5xy^4+y^5$?' + '\n' +
    r'Multiply each $2\times 2 \times 2$ subcube by $x^2$, $xy$, $xy$, $y^2$' +
    '\n' + r'Then reduce monochromatic terms')
va.ax.dist = 11.5

ax = fig.add_subplot(1, 2, 2, projection='3d')
Example #2
0
fig = plt.figure()
ax = fig.add_subplot(1, 3, 1, projection='3d')
ax.set_title('image')
va = VisualArray(arr, fig=fig, ax=ax)  #indices of every cell
cells = va.get_indices_chequerwise(window=(1, ) + w)
va.set_colors(cells.T, color='lawngreen', basecolor='aqua')
va.vizualize(fixview=True, axis_labels=(None, 'axis=1', 'axis=0'))

ax = fig.add_subplot(1, 3, 2, projection='3d')
va2 = VisualArray(va.arr, va.colors, fig=fig, ax=ax)  #shape: (1, 8, 12)
shape = (va2.arr.shape[1] // w[0], w[0], va2.arr.shape[2] // w[1], w[1])
ax.set_title(f'image.reshape{shape}')
va2.reshape(shape)  #shape: (4, 2, 3, 4)
new_arr, new_colors = va2.arr.copy(), va2.colors.copy()
va2.permute(shape)
va2.vizualize(fixview=True, axis_labels=('axis=0', 'axis=1', 'axis=2'))


def argmin(arr):
    #bug...
    a2 = arr.argmin(axis=1)
    a4 = arr.argmin(axis=3)
    a1, a3 = np.indices((arr.shape[0], arr.shape[2]))
    x, y, z, t = zip(*np.broadcast(a1, a2, a3, a4))
    return x, y, z, t


ax = fig.add_subplot(1, 3, 3, projection='3d')
va3 = VisualArray(new_arr, new_colors, fig=fig, ax=ax)  #shape: (1, 8, 12)
ax.set_title(f'image.reshape{shape}.max(axis=(1,3)) \n Not implemented yet')
Example #3
0
import numpy as np
import matplotlib.pyplot as plt
from numpyviz import VisualArray

num = 2
x = np.linspace(0, 99, num)
arr = np.meshgrid(x, x, x, x)[0].astype(int)  #at first cube is 4 dimensional
fig = plt.figure('dimension')
ax = fig.add_subplot(2, 3, 1, projection='3d')
ax.set_title(f'meshgrid(x,x,x,x)[0]' + '\n' +
             f' of shape=({num},{num},{num},{num})')
va = VisualArray(arr.reshape((-1, num, num)), fig=fig, ax=ax)
va.set_colors(va.get_indices().T, color='lawngreen', basecolor='aqua')
va.permute(arr.shape)
va.vizualize(fixview=True, axis_labels=('axis=0+3', 'axis=1', 'axis=2'))

arr2 = arr.reshape(4, num**4 // 4)
ax = fig.add_subplot(2, 3, 2, projection='3d')
ax.set_title(f'meshgrid(x,x,x,x)[0].reshape(4, {num} ** 4 // 4)')
va = VisualArray(arr2, fig=fig, ax=ax)
va.set_colors(va.get_indices().T, color='lawngreen', basecolor='aqua')
va.vizualize(fixview=True, axis_labels=(None, 'axis=0', 'axis=1'))
ax.dist = 11

arr3 = np.stack(np.meshgrid(x, x, x, x), axis=-1).astype(int)
ax = fig.add_subplot(2, 3, 4, projection='3d')
ax.set_title(f'st = np.stack(np.meshgrid(x,x,x,x), axis=-1)')
va = VisualArray(arr3.reshape((-1, num, num)), fig=fig, ax=ax)
va.set_colors(va.get_indices().T, color='lawngreen', basecolor='aqua')
va.permute(arr3.shape)
va.vizualize(fixview=True, axis_labels=('axis=0+3', 'axis=1+4', 'axis=2'))
Example #4
0
va1.set_colors(va1.get_indices().T, color='lightgreen', basecolor='aqua')
va1.vizualize(fixview=True,
              axis_labels=(None, 'axis=0', 'axis=1'),
              usetex=False,
              scale=1.2)
va1.ax.dist = 12
va1.azim, va1.elev = -90, 45

ax = fig.add_subplot(2, 3, 2, projection='3d')
va2 = VisualArray(arr, fig=fig, ax=ax)
va2.ax.set_title(f'input <-> input.reshape((4, 3, 4, 3))')
w = (3, 3)
shape = (arr.shape[1] // w[0], w[0], arr.shape[2] // w[1], w[1])
print(shape)
va2.set_colors(va2.get_indices().T, color='lightgreen', basecolor='aqua')
va2.permute(shape)
va2.vizualize(fixview=True,
              axis_labels=('axis=0+3', 'axis=1', 'axis=2'),
              usetex=False,
              scale=1.2)
va2.ax.dist = 8

ax = fig.add_subplot(2, 3, 3, projection='3d')
old_shape = arr.shape
arr = arr.reshape(shape)
arr = arr.swapaxes(1, 0)
arr_final = arr.swapaxes(0, 2)
arr_final_shape = arr_final.shape
shape = arr.shape
arr = arr.reshape(old_shape)