np.mgird np.ogrid
np.ogrid:
address:https://docs.scipy.org/doc/numpy/reference/generated/numpy.ogrid.html
returns an open (i.e. not fleshed out) mesh-grid when indexed, only one dimension of each returned array is greater than 1.
The dimension and number of the output arrays are equal to the number of indexing dimensions.
If the step length is not a complex number, then the stop is not inclusive.
if the step length is a complex number (e.g. 5j), then the integer part of its magnitude is interpreted as specifying the number of points to create between the start and stop values, where the stop value is inclusive.
上面几条翻译过来就是:
返回数组的维度只有一个大于1.
返回数组的个数和维度等于输入时索引维度的个数.
若步长不是复数,就不包含stop.
若步长是复数,其整数部分表示在start和stop之间创建的点数(start和stop也算),包含stop.
下面示例解释前2条:
a, b, c = np.ogrid[0:2, 0:2, 0:2]
print(a.shape, b.shape, c.shape)
print(a)
print(b)
print(c) a, b, c, d = np.ogrid[0:2, 0:2, 0:2, 0:2]
print(a.shape, b.shape, c.shape, d.shape) result:
(2, 1, 1) (1, 2, 1) (1, 1, 2)
[[[0]] [[1]]]
[[[0]
[1]]]
[[[0 1]]]
(2, 1, 1, 1) (1, 2, 1, 1) (1, 1, 2, 1) (1, 1, 1, 2)
解释第3条:
a, b, c = np.ogrid[0:4:2, 0:5:3, 0:5:1]
print(a.shape, b.shape, c.shape)
print(a)
print(b)
print(c) result:
(2, 1, 1) (1, 2, 1) (1, 1, 5)
[[[0]] [[2]]] # 不包含stop
[[[0]
[3]]]
[[[0 1 2 3 4]]] # 不包含stop
解释第4条:
a, b, c = np.ogrid[0:4:3j, 0:5:3j, 0:5:4j]
print(a.shape, b.shape, c.shape)
print(a)
print(b)
print(c) result:
(3, 1, 1) (1, 3, 1) (1, 1, 4)
[[[0.]] [[2.]] [[4.]]] # 包含stop
[[[0. ]
[2.5]
[5. ]]]
[[[0. 1.66666667 3.33333333 5. ]]] # 包含stop
np.mgrid:
address: https://docs.scipy.org/doc/numpy/reference/generated/numpy.mgrid.html
除第1条不同外,其他3条完全一样:
returns an dense (or fleshed out) mesh-grid when indexed, each returned argument has the same shape.
N = 100
X, Y = np.mgrid[-3:3:complex(0, N), -2:2:complex(0, N)]
print(X.shape, Y.shape) # (100, 100) (100, 100)
# X是每行都相等,每列递增;Y是每行都相等,每列递增
print(X)
# [[-3. -3. -3. ... -3. -3.
# -3. ]
# [-2.93939394 -2.93939394 -2.93939394 ... -2.93939394 -2.93939394
# -2.93939394]
# [-2.87878788 -2.87878788 -2.87878788 ... -2.87878788 -2.87878788
# -2.87878788]
# ...
# [ 2.87878788 2.87878788 2.87878788 ... 2.87878788 2.87878788
# 2.87878788]
# [ 2.93939394 2.93939394 2.93939394 ... 2.93939394 2.93939394
# 2.93939394]
# [ 3. 3. 3. ... 3. 3.
# 3. ]]
print(Y)
# [[-2. -1.95959596 -1.91919192 ... 1.91919192 1.95959596
# 2. ]
# ...
# [-2. -1.95959596 -1.91919192 ... 1.91919192 1.95959596
# 2. ]]
np.meshgrid:
numpy.meshgrid(x, y)
Return coordinate matrices from two coordinate vectors.
参数: x, y: Two 1-D arrays representing the x and y coordinates of a grid.
返回: X, Y: For vectors x, y with lengths Nx=len(x) and Ny=len(y), return X, Y where X and Y are (Ny, Nx) shaped arrays with the elements of x and y repeated to fill the matrix along the first dimension for x, the second for y. # 返回两个shape为 (Ny, Nx) 的数组,其中第1个数组用x填充,第2个数组用y填充。
meshgrid is very useful to evaluate functions on a grid.
>>> X, Y = np.meshgrid([1,2,3], [4,5,6,7])
>>> X
array([[1, 2, 3],
[1, 2, 3],
[1, 2, 3],
[1, 2, 3]])
>>> Y
array([[4, 4, 4],
[5, 5, 5],
[6, 6, 6],
[7, 7, 7]])
np.mgird np.ogrid的更多相关文章
- 区分range() , np.arange() , np.linspace()
content: range() np.arange() np.linspace() 一.range(start, stop, step) 1.range() 为 python 自带函数 2.生成一个 ...
- scikit-learn工具学习 - random,mgrid,np.r_ ,np.c_, scatter, axis, pcolormesh, contour, decision_function
yuanwen: http://blog.csdn.net/crossky_jing/article/details/49466127 scikit-learn 练习题 题目:Try classify ...
- Python 中的几种矩阵乘法 np.dot, np.multiply, *【转】
本文转载自:https://blog.csdn.net/u012609509/article/details/70230204 Python中的几种矩阵乘法1. 同线性代数中矩阵乘法的定义: np.d ...
- Numpy:np.vstack()&np.hstack() flat/flatten
一 . np.vstack: 按垂直方向(行顺序)堆叠数组构成一个新的数组 In[3]: import numpy as np In[4]: a = np.array([[1,2,3]]) a.sh ...
- Python 中的几种矩阵乘法 np.dot, np.multiply, *
使用array时,运算符 * 用于计算数量积(点乘),函数 dot() 用于计算矢量积(叉乘).使用matrix时,运算符 * 用于计算矢量积,函数 multiply() 用于计算数量积. 下面是使用 ...
- numpy-np.ceil,np.floor,np.expand_dims方法
np.ceil(多维数组):对多维数组的各个数向上取整 np.floor(多维数组):对多维数组的各个数向下取整 np.expand_dims(x,axis = 0):在x的第一维度上插入一个维度,a ...
- h5py报错:FutureWarning: Conversion of the second argument of issubdtype from `float` to `np.floating` is deprecated. In future, it will be treated as `np.float64 == np.dtype(float).type`.
导入h5py的时候,报错: /home/harris/anaconda3/lib/python3.6/site-packages/h5py/__init__.py:36: FutureWarning: ...
- numpy 常用工具函数 —— np.bincount/np.average
numpy 常用工具函数 —— np.bincount/np.average numpy 常用api(一) numpy 常用api(二) 一个函数提供 random_state 的关键字参数(keyw ...
- Python中range, np.arange, np.linspace的区别
目录 range np.arange np.linspace range 特点 range()是python内置函数,指定开始值,终值和步长生成等差数列的一维数组 不包含终值 步长只能是整数,生成整数 ...
随机推荐
- postgresql 窗口函数排序实例
经常遇到一种应用场景,将部分行的内容进行汇总.比较.排序. 比如数据表名称test.test2 select num,province from test.test2 得到结果: ;"黑龙江 ...
- Ubuntu16.04上使用Anaconda3的Python3.6的pip安装UWSGI报错解决办法
具体报错信息: lto1: fatal error: bytecode stream generated with LTO version 6.0 instead of the expected 4. ...
- Python操作redis系列之 列表(list) (五)
# -*- coding: utf- -*- import redis r =redis.Redis(host=,password=") 1. Lpush 命令将一个或多个值插入到列表头部. ...
- mechanize (1)
最近看的关于网络爬虫和模拟登陆的资料,发现有这样一个包 mechanize ['mekə.naɪz]又称为机械化的意思,确实文如其意,确实有自动化的意思. mechanize.Browser and ...
- SQLServer 数据库变成单个用户后无法访问问题的解决方法
USE master; GO DECLARE @SQL VARCHAR(MAX); SET @SQL='' SELECT @SQL=@SQL+'; KILL '+RTRIM(SPID) FROM ma ...
- 第三部分:Android 应用程序接口指南---第二节:UI---第七章 通知
第7章 通知 一个通知是一条消息他是显示于你应用程序之外的一个界面中.当你告诉系统要发布一个通知时,它首先作为一个icon出现在通知区域.为了看见通知的细节,用户可以点击通知区域展开一个新的界面.下面 ...
- 腾讯云SpringBoot部署 + HTTPS配置
springboot可以打包为jar和war,jar不多说了,最近的一个工程需要打包为war发布,大致说一下吧: 先看一下项目的大致结构: 第一步,需要排除springboot自带的tomcat插件 ...
- How can R and Hadoop be used together?
Referer: http://www.quora.com/How-can-R-and-Hadoop-be-used-together/answer/Jay-Kreps?srid=OVd9&s ...
- Instrumentation 功能介绍(javaagent)
利用 Java 代码,即 java.lang.instrument 做动态 Instrumentation 是 Java SE 5 的新特性,它把 Java 的 instrument 功能从本地代码中 ...
- 全面理解Java内存模型(JMM)
理解Java内存区域与Java内存模型Java内存区域 Java虚拟机在运行程序时会把其自动管理的内存划分为以上几个区域,每个区域都有的用途以及创建销毁的时机,其中蓝色部分代表的是所有线程共享的数据区 ...