1.1通过位置匹配参数
print(“Starting gradient descent at b = {0}, w = {1}, error = {2}”
.format(initial_b, initial_w,
compute_error_for_line_given_points(initial_b, initial_w, points))
)‘{0}, {1}, {2}’.format(‘a’, ‘b’, ‘c’)
‘a, b, c’‘{}, {}, {}’.format(‘a’, ‘b’, ‘c’) # 3.1+版本支持
‘a, b, c’‘{2}, {1}, {0}’.format(‘a’, ‘b’, ‘c’)
‘c, b, a’‘{2}, {1}, {0}’.format(*‘abc’) # 可打乱顺序
‘c, b, a’‘{0}{1}{0}’.format(‘abra’, ‘cad’) # 可重复
‘abracadabra’
1.2numpy中的array数组常见操作
2.1
创建一维数组与二维数组
# 一维数组
a = np.array([1, 2, 3])
b = np.array([1., 2., 3.])
# 二维数组
c = np.array([[1., 2.], [3., 4.]])
d = np.array([[1, 2], [3, 4]])
e = np.array([[1, 2], [3, 4]], dtype=complex)
print(a, a.dtype)
print(b, b.dtype)
print(c, c.dtype)
print(d, d.dtype)
print(e, e.dtype)