摘要: # 来源:NumPy Essentials ch4 步长 # 步长是每个维度相邻两个元素的偏移差值 import numpy as np x = np.arange(8, dtype = np.int8) x # array([0, 1, 2, 3, 4, 5, 6, 7]) # x 是一维数组,步 阅读全文
posted @ 2017-06-14 20:50 绝不原创的飞龙 阅读(10) 评论(0) 推荐(0) 编辑
摘要: # 来源:NumPy Essentials ch3 向量化 import numpy as np # NumPy 数组的运算是向量化的 # 数组和标量运算是每个元素和标量运算 x = np.array([1, 2, 3, 4]) x + 1 # array([2, 3, 4, 5]) # 数组和数组 阅读全文
posted @ 2017-06-14 20:47 绝不原创的飞龙 阅读(10) 评论(0) 推荐(0) 编辑
摘要: # 来源:NumPy Essentials ch2 数组索引和切片 # 创建 100x100 个 0~1 随机数 x = np.random.random((100, 100)) # 取第 42 行 87 列的元素(从零开始) y = x[42, 87] # 取第 k 行的所有元素 # 等价于 x[ 阅读全文
posted @ 2017-06-14 20:44 绝不原创的飞龙 阅读(11) 评论(0) 推荐(0) 编辑
摘要: # 来源:NumPy Cookbook 2e Ch11 np.random.seed(44) a = np.random.random_integers(-4, 4, 7) print(a) # [ 0 -1 -3 -1 -4 0 -1] # ufunc 的 at 方法可以对数组元素部分调用 np. 阅读全文
posted @ 2017-06-14 20:41 绝不原创的飞龙 阅读(16) 评论(0) 推荐(0) 编辑
摘要: # 来源:NumPy Cookbook 2e Ch10 加载示例数据集 from __future__ import print_function from sklearn import datasets # datasets.load_? 用于加载不同的数据集 print filter(lambd 阅读全文
posted @ 2017-06-14 20:38 绝不原创的飞龙 阅读(8) 评论(0) 推荐(0) 编辑
摘要: # 来源:NumPy Cookbook 2e ch6 创建通用函数 from __future__ import print_function import numpy as np # 我们需要定义对单个元素操作的函数 def double(a): return 2 * a # frompyfunc 阅读全文
posted @ 2017-06-14 20:33 绝不原创的飞龙 阅读(10) 评论(0) 推荐(0) 编辑