2017.7.8 & numpy基础
来源:互联网 发布:阿里云关机还收费吗 编辑:程序博客网 时间:2024/06/05 22:42
1.nump
二阶单位阵
d = np.eye(2) # Create a 2x2 identity matrixprint(d) # Prints "[[ 1. 0.] # [ 0. 1.]]"
整型索引会降低矩阵的维度,切片索引却不会
row_r1 = a[1, :] # Rank 1 view of the second row of arow_r2 = a[1:2, :] # Rank 2 view of the second row of aprint(row_r1, row_r1.shape) # Prints "[5 6 7 8] (4,)"print(row_r2, row_r2.shape) # Prints "[[5 6 7 8]] (1, 4)"
numpy中关于array整型Index的一个点
两个矩阵,确定一个位置
a = np.array([[1,2], [3, 4], [5, 6]])# An example of integer array indexing.# The returned array will have shape (3,) andprint(a[[0, 1, 2], [0, 1, 0]]) # Prints "[1 4 5]"# The above example of integer array indexing is equivalent to this:print(np.array([a[0, 0], a[1, 1], a[2, 0]])) # Prints "[1 4 5]"
numpy强制类型转换
x = np.array([1, 2], dtype=np.int64) # Force a particular datatypeprint(x.dtype) # Prints "int64"
numpy中矩阵加减乘除开放运算
x = np.array([[1,2],[3,4]], dtype=np.float64)y = np.array([[5,6],[7,8]], dtype=np.float64)print(x + y)print(np.add(x, y))print(x - y)print(np.subtract(x, y))*这的乘积,是矩阵各元素的乘积,不是矩阵相乘,向量和*print(x * y)print(np.multiply(x, y))print(x / y)print(np.divide(x, y))print(np.sqrt(x))
dot用法:既可以用于vectors*vectors(各项之积的和);用于matrix*vectors;还可用于matrix*matrix
import numpy as npx = np.array([[1,2],[3,4]])y = np.array([[5,6],[7,8]])v = np.array([9,10])w = np.array([11, 12])# Inner product of vectors; both produce 219print(v.dot(w))print(np.dot(v, w))# Matrix / vector product; both produce the rank 1 array [29 67]print(x.dot(v))print(np.dot(x, v))# Matrix / matrix product; both produce the rank 2 array# [[19 22]# [43 50]]print(x.dot(y))print(np.dot(x, y))
遇到有趣的tile函数
#列方向上重复两次变为【1,2,1,2】a = np.tile([1,2], 2)#行方向重复三次,列方向重复2次,变为:#【1,2,1,2】#【1,2,1,2】#【1,2,1,2】a = np.tile([1,2], (3, 2))
x = np.array([[1,2,3], [4,5,6], [7,8,9], [10, 11, 12]])v = np.array([1, 0, 1])y = x + v # Add v to each row of x using broadcastingprint(y) # Prints "[[ 2 2 4] # [ 5 5 7] # [ 8 8 10] # [11 11 13]]"
今天就到这,明天是生日,出去玩耍
阅读全文
0 0
- 2017.7.8 & numpy基础
- Numpy 基础
- Numpy 基础
- Numpy:基础
- numpy基础
- Numpy基础
- numpy基础
- NumPy 基础
- Numpy基础
- numpy 基础
- NumPy基础
- Numpy基础
- numpy 基础
- 8、NumPy 基础:数组和矢量运算
- Numpy 基础数据类型 (一)
- Numpy基础笔记
- python numpy基础-
- python numpy 基础2
- Python--序列学习(三)--元组
- SSH密钥登录远程主机
- struts2中Action配置之注解配置
- Android cookieManager & OKHttp以及EasyPlayerPro的媒体流的认证的实现
- Python--序列学习(四)--字典
- 2017.7.8 & numpy基础
- ORA-28040: No matching authentication protocol
- React Native学习笔记(3)--TextInput组件
- HTML5基础知识
- Tensorflow-基本操作基本知识
- 接口到底有什么用
- 剑指offer-13-反转链表
- 微信开发--分享到朋友圈和发送给好友
- 2009-2010 ACM-ICPC, NEERC, Southern Subregional Contest B kakuro