ひとり勉強ログ

ITエンジニアの勉強したことメモ

【ゼロから作るDeepLearning】1章 python入門

1.5 Numpy

1.5.5 ブロードキャスト

>>> import numpy as np
>>> A = np.array([[1,2], [3,4]])
>>> B = np.array([10,20])
>>> A*B
array([[10, 40],
       [30, 80]])

1.6 Matplotlib

1.6.1 単純なグラフの描画

>>> import numpy as np
>>> import matplotlib.pyplot as plt
>>> x = np.arange(0, 6, 0.1)
>>> y = np.sin(x)
>>> plt.plot(x, y)
[<matplotlib.lines.Line2D object at 0x7fdf41037e50>]
>>> plt.show()

1.6.2 pyplotの機能

>>> import numpy as np
>>> import matplotlib.pyplot as plt
>>> x = np.arange(0, 6, 0.1)
>>> y1 = np.sin(x)
>>> y2 = np.cos(x)
>>> plt.plot(x, y1, label="sin")
[<matplotlib.lines.Line2D object at 0x7fdf410f9e80>]
>>> plt.plot(x, y2, linestyle = "--", label="cos")
[<matplotlib.lines.Line2D object at 0x7fdf41107610>]
>>> plt.xlabel("x")
Text(0.5, 0, 'x')
>>> plt.ylabel("y")
Text(0, 0.5, 'y')
>>> plt.title('sin & cos')
Text(0.5, 1.0, 'sin & cos')
>>> plt.legend()
<matplotlib.legend.Legend object at 0x7fdf410e0af0>
>>> plt.show()