上一页 1 ··· 355 356 357 358 359 360 361 362 363 ··· 404 下一页
摘要: # 来源:NumPy Essentials ch5 矩阵 import numpy as np ndArray = np.arange(9).reshape(3,3) # matrix 可以从 ndarray 直接构建 x = np.matrix(ndArray) # identity 用于构建单位 阅读全文
posted @ 2017-06-15 09:34 绝不原创的飞龙 阅读(14) 评论(0) 推荐(0) 编辑
摘要: # 来源: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) 编辑
摘要: # 来源:NumPy Cookbook 2e Ch5 将图像加载进内存 import numpy as np import matplotlib.pyplot as plt # 首先生成一个 512x512 的图像 # 在里面画 30 个正方形 N = 512 NSQUARES = 30 # 初始化 阅读全文
posted @ 2017-06-12 20:10 绝不原创的飞龙 阅读(18) 评论(0) 推荐(0) 编辑
摘要: # 来源:NumPy Cookbook 2e Ch4 使用缓冲区协议 # 协议在 Python 中相当于接口 # 是一种约束 import numpy as np import Image # from PIL import Image (Python 3) import scipy.misc le 阅读全文
posted @ 2017-06-12 09:24 绝不原创的飞龙 阅读(8) 评论(0) 推荐(0) 编辑
摘要: 斐波那契数的第 n 项 # 来源:NumPy Cookbook 2e Ch3.1 import numpy as np # 斐波那契数列的每个新项都由之前的两项相加而成 # 以 1 和 2 开始,前 10 项为: # 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, ... # 阅读全文
posted @ 2017-06-11 16:59 绝不原创的飞龙 阅读(16) 评论(0) 推荐(0) 编辑
上一页 1 ··· 355 356 357 358 359 360 361 362 363 ··· 404 下一页