原标题:教程 | 基础入门:深度学习矩阵运算的概念和代码实现

什么是线性代数?

线性代数为什么如此实用?

x = [1,2,3]

y = [2,3,4]

product = []

for i in range(len(x)):

product.append(x[i]*y[i])

x = numpy.array([1,2,3])

y = numpy.array([2,3,4])

x * y

线性代数怎样应用到深度学习?

向量

x = np.array([2,3,4])

y + x = [3, 5, 7]

y - x = [-1, -1, -1]

y / x = [.5, .67, .75]

x = np.array([2,3,4])

y * x = [2, 6, 12]

矩阵

[1,2,3],

[4,5,6]

])

a.shape == (2,3)

[1,2,3]

])

b.shape == (1,3)

[[1,2],

[3,4]])

a + 1

[[2,3],

[4,5]]

[1,2],

[3,4]

])

b = np.array([

[1,2],

[3,4]

])

[[2, 4],

[6, 8]]

[[0, 0],

[0, 0]]

# Different no. of columns

# but has one column so this works

a * b

[[ 3, 4],

[10, 12]]

# Different no. of rows

# but has one row so this works

b * c

[[ 3, 8],

[5, 12]]

# Different no. of rows

# but both and meet the

# size 1 requirement rule

a + c

[[2, 3],

[3, 4]]

[[2,3],

[2,3]])

b = np.array(

[[3,4],

[5,6]])

a * b

[[ 6, 12],

[10, 18]]

[1, 2],

[3, 4]])

[[1, 3],

[2, 4]]

矩阵乘法

使用 Numpy 进行矩阵乘法运算

[1, 2]

])

a.shape == (1,2)

[3, 4],

[5, 6]

])

b.shape == (2,2)

mm = np.dot(a,b)

mm == [13, 16]

mm.shape == (1,2)

责任编辑: