예제 #1
0
if '__file__' in globals():
    import os
    import sys
    sys.path.append(os.path.join(os.path.dirname(__file__), '..'))
import numpy as np

from dezero import Variable

if __name__ == '__main__':

    x = Variable(np.array([[0, 1, 2], [3, 4, 5]]))
    y = x.reshape((6, ))
    y.backward(retain_grad=True)
    print(x.grad)

    x = Variable(np.array([[1, 2, 3], [4, 5, 6]]))
    y = x.T
    y.backward()
    print(x.grad)
 def test_reshape_var_method_tuple(self):
     x = Variable(np.array([1, 2, 3, 4, 5, 6]))
     y = x.reshape(2, 3)
     assert y.shape == (2, 3)
예제 #3
0
if '__file__' in globals():
    import os, sys
    sys.path.append(os.path.join(os.path.dirname(__file__), '..'))

import numpy as np
from dezero import Variable
import dezero.functions as F


x = Variable(np.array([[1, 2, 3], [4, 5, 6]]))
y = F.reshape(x, (6,))
y.backward(retain_grad=True)
print(x.grad)

x = Variable(np.random.randn(1, 2, 3))
y0 = x.reshape((2, 3))
print(y0)
y1 = x.reshape(2, 3)
print(y1)

x = Variable(np.array([[1, 2, 3], [4, 5, 6]]))
y = F.transpose(x)
y.backward()
print(x.grad)
 def test_reshape_var_method(self, input, expected):
     x = Variable(np.array([1, 2, 3, 4, 5, 6]))
     y = x.reshape(input)
     assert y.shape == expected