I am a novice of Chainer. I am doing by the Guides. However, I find something that I think it is strange. In the Docs » Guides » Variable Chapter, I write the blow code:
x = Variable(np.array([[1, 2, 3], [4, 5, 6]], dtype=np.float32))
y = 2.0 * x
# y.grad = np.zeros((2, 3), dtype=np.float32)
y.backward()
print(x.grad)
print(y.data)
Then, there is a error, the error message is :
TypeError: unsupported operand type(s) for *: 'float' and 'NoneType'
And when we delete the annotated sign, the code is :
x = Variable(np.array([[1, 2, 3], [4, 5, 6]], dtype=np.float32))
y = 2.0 * x
y.grad = np.zeros((2, 3), dtype=np.float32)
y.backward()
print(x.grad)
print(y.data)
Then everything is ok.
So it seems that it must to assign the initial grad to the variable of y. I think this is strange. Should it be one as a default value?
I am looking for your explanation for that, thank you very much!