Numpy_01
>>> from numpy import pi
>>> np.linspace(0, 2, 9)
array([0. , 0.25, 0.5 , 0.75, 1. , 1.25, 1.5 , 1.75, 2. ])
>>> x = np.linspace(0, 2*pi, 100)
>>> y = np.sin(x)
>>> import matplotlib.pyplot as plt
>>> plt.plot(x, y, 'o')
[<matplotlib.lines.Line2D object at 0x0000021025D65BA8>]
>>> plt.show()
Numpy_02
>>> import numpy as np
>>> import matplotlib.pyplot as plt
>>> from numpy import pi
>>> x = np.linspace(0, 2*pi, 100)
>>> y1 = np.sin(x)
>>> y2 = np.cos(x)
>>> # sin
>>> plt.plot(x, y1, 'g')
[<matplotlib.lines.Line2D object at 0x000002C068E4C940>]
>>> # cos
>>> plt.plot(x, y2, 'r')
[<matplotlib.lines.Line2D object at 0x000002C068E4CA90>]
>>> # x = 0
>>> y = np.linspace(-1, 1, 100)
>>> plt.plot(x*0, y, 'b')
[<matplotlib.lines.Line2D object at 0x000002C068E4CCF8>]
>>> # x = 2*pi
>>> plt.plot(x*0 + 2*pi, y, 'b')
[<matplotlib.lines.Line2D object at 0x000002C068E4CD68>]
>>> # y = 1
>>> plt.plot(x, y*0 + 1, 'b')
[<matplotlib.lines.Line2D object at 0x000002C05EEB4C50>]
>>> # y = -1
>>> plt.plot(x, y*0 - 1, 'b')
[<matplotlib.lines.Line2D object at 0x000002C068E61E10>]
>>> plt.show()
Numpy_03
>>> A = np.array([[1,1],
[0,1]])
>>> B = np.array([[2,0],
[3,4]])
>>> A * B # 点乘,对应点的乘积
array([[2, 0],
[0, 4]])
>>> A @ B # 矩阵乘法
array([[5, 4],
[3, 4]])
>>> A.dot(B) # 矩阵乘法
array([[5, 4],
[3, 4]])
>>> A * 2 # 乘以数字
array([[2, 2],
[0, 2]])
>>> A / 2 # 除以数字
array([[0.5, 0.5],
[0. , 0.5]])
>>> A + B # 矩阵加法
array([[3, 1],
[3, 5]])
>>> A - B # 矩阵减法
array([[-1, 1],
[-3, -3]])
>>> B ** 2 # 对矩阵每个元素取平方
array([[ 4, 0],
[ 9, 16]], dtype=int32)