🥥Python和Julia线性代数(矢量矩阵最小二乘)
Python | 数学 | Julia | 线性代数 | 矢量 | 最小二乘法 | 欧氏范数 | 均方根值 | 泰勒近似 | 回归模型 | 聚类 |-均值聚类 | 正交向量 | 格兰姆-施密特算法 | 线性动力系统 | 最小二乘拟合 | 最小二乗分类 | 非线性最小二乘法
矢量(向量)
向量是有序的有限数字列表。 向量通常写成垂直数组,用方括号或弯括号括起来,如
它们也可以写成用逗号分隔并用括号括起来的数字。 在这种符号风格中,上面的向量被写为
Python示例:
import numpy as np
x = np.array([-1.1,0.0,3.6,-7.2])
y = np.array([-1.1,0.0,3.6,-7.2])
x,y, len(x), len(y)输出:
(array([-1.1,  0. ,  3.6, -7.2]), array([-1.1,  0. ,  3.6, -7.2]), 4, 4)块或堆叠向量
x = np.array([1,-2]); y = np.array([1,1,0]);
z = np.concatenate((x,y))
z输出:
array([ 1, -2,  1,  1,  0])子向量和切片
x = np.array([9,4,3,0,5])
y = x[1:4]
y输出:
array([4, 3, 0])一阶差分向量
x = np.array([1,0,0,-2,2])
np.array([x[i+1]-x[i] for i in range(len(x)-1)])输出:
array([-1,  0, -2,  4])矩阵
矩阵是写在方括号之间的矩形数组,如
使用大圆括号代替方括号也很常见,如
Python示例
import numpy as np
import numpy.linalg as npl
import math
import matplotlib.pyplot as plt
pg112 = np.matrix([[0,1,1,0],[1,0,0,1],[0,0,0,1],[1,0,0,0]])
G = nx.from_numpy_matrix(pg112)
pos = nx.layout.spring_layout(G)
node_sizes = [3 + 10 * i for i in range(len(G))]
M = G.number_of_edges()
edge_colors = range(2, M + 2)
edge_alphas = [(5 + i) / (M + 4) for i in range(M)]
nodes = nx.draw_network_nodes(G, pos, node_size=node_sizes, node_color='blue', with_labels=True)
edges = nx.draw_network_edges(G, pos, node_size=node_sizes, arrowstyle='->',
                               arrowsize=10, edge_color=edge_colors,
                               edge_cmap=plt.cm.Blues, width=2)
ax = plt.gca()
ax.set_axis_off()
plt.show()最小二乘法
Python和Julia处理线性代数
Last updated
Was this helpful?
