我是这样理解的哈 。pdf文档第二个结果应该是w的转置。书中的第一个A转置是为了方便梯度下降的时候与x相加方便,正好A的转置的一行求和在和x相加。x也是个列向量。pdf中的原始的w矩阵,每一列刚好是各个y对x_i的影响,所以w矩阵列元素相加以后就是梯度下降计算的delta,这个时候是一个行向量显然不方便运算,转置一下正好和同是列向量的x相减方便。
1、
code:
def f(x):
return x**3 - 1/x
x = np.arange(0, 3, 0.1)
plot(x, [f(x), 4*x -4], ‘x’, ‘f(x)’, legend=[‘f(x)’, ‘Tangent line (x=1)’])
result:
2、the answer of the second question:
[6x1, 5e**x2]T
我想问一个问题,怎么样查看d2l.plt.gca()这个函数的用法,或者如何查看其源码?(书籍P66
pypi上的d2l包,我的IPython版本已经弃用了set_matplotlib_formats (参考这个issue:Deprecated use of IPython.display.set_matplotlib_formats · Issue #1842 · scverse/scanpy · GitHub)
如果出现IPython报AttributeError说找不到set_matplotlib_formats属性,可能就是这个原因
我的解决办法:在 d2l/tensorflow.py中添加如下代码:
import warnings
# Issue: Deprecated use of IPython.display.set_matplotlib_formats #1842
try:
warnings.showwarning("[ Info ] IPython.display.set_matplotlib_formats is deprecated, use matplotlib_inline.backend_inline.set_matplotlib_formats instead", DeprecationWarning, __file__, 1)
try:
IPythonDisplaySetMatplotlibFormats_ = display.set_matplotlib_formats
except AttributeError:
pass
import matplotlib_inline.backend_inline
display.set_matplotlib_formats = matplotlib_inline.backend_inline.set_matplotlib_formats
warnings.showwarning("[Succeed] IPython.display.set_matplotlib_formats is deprecated, use matplotlib_inline.backend_inline.set_matplotlib_formats instead", DeprecationWarning, __file__, 1)
except ImportError:
warnings.showwarning("[ Info ] cannot import matplotlib_inline.backend_inline, using IPython.display.set_matplotlib_formats instead", ImportError, __file__, 1)
display.set_matplotlib_formats = IPythonDisplaySetMatplotlibFormats_
warnings.showwarning("[Succeed] IPython.display.set_matplotlib_formats is deprecated, use matplotlib_inline.backend_inline.set_matplotlib_formats instead", DeprecationWarning, __file__, 1)
finally:
try:
del IPythonDisplaySetMatplotlibFormats_
except NameError:
warnings.showwarning("[ Info ] hook failed, continue...", NameError, __file__, 1)
pass
或者直接用本书github仓库里的d2l,那个是直接用的matplotlib_inline.backend_inline.set_matplotlib_formats