np.arange([start, ]stop, [step, ]dtype=None)
start : 起始值,默认值为0,Optional(可选)。
end : 结束值(不含)。
step : 步长,默认值为1
dtype :默认为None,从其他输入值中推测,Optional(可选)
import numpy as np
record = [0.1, 0.01, 0.001]
len(record) = 3
np.arange(0,len(record),1) = np.arange(0,3,1) = [0,1,2]
np.arange(1,len(record)+1,1) = np.arange(1,4,1) = [1,2,3]
plt.plot(x, y, format_string, **kwargs)
import matplotlib.pyplot as plt
t=[1,2,3,4,5]
y=[3,4,5,6,7]
plt.plot(t, y)
因此两个optimizer出来的loss可以这样画:
num1 = np.arange(1, len(loss1_record)+1, 1)
num2 = np.arange(1, len(loss2_record)+1, 1)
num = num1 + num2
loss_record = np.add(loss1_record , loss2_record)
plt.plot(num1, loss1_record,label='loss_Adam')
plt.plot(num2, loss2_record,label='loss_L-BFGS-B')
plt.plot(num, loss_record,label='total loss')
#plt.title(f'loss: epochs={epochs}, h = {h}, minloss = {round(local_min,6)}')
plt.ylabel('loss')
plt.xlabel('x')
plt.legend()