一、数学基础
二、numpy
一、数学基础
关键字:求导、偏导、梯度、复合函数求导链式法则
矩阵的转置、矩阵加减、矩阵乘法【矩阵乘法不满足交换律】
二、numpy
#coding:utf-8
import numpy as np
print np.__version__
# 1- create narray
array = np.array([1,2,3],dtype=np.uint8)
print "array:",array
# 2- zeros
mat1 = np.zeros((2,3)) #(2,3) tuple
print "mat1:",mat1
# 3- 高维矩阵
mat2 = np.zeros((1,2,3,4))
print mat2.shape
print mat2.size
# 4- 标准矩阵运算
# (1) 标量与矩阵相乘
scalar = 2
mat = np.ones((2,3))
mat3 = scalar * mat
print "mat3:",mat3
# (2) 矩阵转置 mat.T
mat = np.zeros((2,3))
tmat = mat.T
print mat.shape,tmat.shape
mat4 = np.array((1,2,3))
print "mat4:",mat4
tmat4 = mat4.T
print mat4.shape,tmat4.shape
# (3) 矩阵的加法
print "add--------------------"
mat1 = np.array([[1,2],[3,4]])
mat2 = np.zeros((2,2))
mat3 = mat1 + mat2
print "mat3:",mat3
# (4) 矩阵的乘法
print "multi------------------"
mat1 = np.array([[1,2],[3,4]])
mat2 = np.ones((2,2))
mat3 = mat1.dot(mat2)
print "mat3:",mat3
原文地址:https://www.cnblogs.com/Years4Nancy/p/8492521.html