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的更多相关文章

  1. 区分range() , np.arange() , np.linspace()

    content: range() np.arange() np.linspace() 一.range(start, stop, step) 1.range() 为 python 自带函数 2.生成一个 ...

  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 ...

  3. Python 中的几种矩阵乘法 np.dot, np.multiply, *【转】

    本文转载自:https://blog.csdn.net/u012609509/article/details/70230204 Python中的几种矩阵乘法1. 同线性代数中矩阵乘法的定义: np.d ...

  4. 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 ...

  5. Python 中的几种矩阵乘法 np.dot, np.multiply, *

    使用array时,运算符 * 用于计算数量积(点乘),函数 dot() 用于计算矢量积(叉乘).使用matrix时,运算符 * 用于计算矢量积,函数 multiply() 用于计算数量积. 下面是使用 ...

  6. numpy-np.ceil,np.floor,np.expand_dims方法

    np.ceil(多维数组):对多维数组的各个数向上取整 np.floor(多维数组):对多维数组的各个数向下取整 np.expand_dims(x,axis = 0):在x的第一维度上插入一个维度,a ...

  7. 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: ...

  8. numpy 常用工具函数 —— np.bincount/np.average

    numpy 常用工具函数 —— np.bincount/np.average numpy 常用api(一) numpy 常用api(二) 一个函数提供 random_state 的关键字参数(keyw ...

  9. Python中range, np.arange, np.linspace的区别

    目录 range np.arange np.linspace range 特点 range()是python内置函数,指定开始值,终值和步长生成等差数列的一维数组 不包含终值 步长只能是整数,生成整数 ...

随机推荐

  1. 【NLP】Python实例:基于文本相似度对申报项目进行查重设计

    Python实例:申报项目查重系统设计与实现 作者:白宁超 2017年5月18日17:51:37 摘要:关于查重系统很多人并不陌生,无论本科还是硕博毕业都不可避免涉及论文查重问题,这也对学术不正之风起 ...

  2. swift3 单例写法

    import UIKit class SingleOnce { // 单例 static let shared = SingleOnce.init() private init(){} // 其他方法 ...

  3. os.walk() 目录生成器

    目录生成器 Directory tree generator.! walk() 是 generator,直接print() 为  <generator object walk at 0x0000 ...

  4. C++11模版元编程的应用

    1.概述 关于C++11模板元的基本用法和常用技巧,我在程序员2015年2月B<C++11模版元编程>一文(后称前文)中已经做了详细地介绍,那么C++11模版元编程用来解决什么实际问题呢, ...

  5. 扩展layui中的自带字体图标

    项目中,虽然layui的字体图标库中已经有了1000多个图标了,但是也有时候不能满足我们自定义图标的需求,所以需要进行自定义,具体步骤如下: 1.在iconfont上找到自己喜欢的图标,也可以上传ui ...

  6. 去除partner页面消息 自动添加关注者的功能

    某些公司希望在partner页面说些partner的坏话,可是odoo居然自动添加了partner关注,这就尴尬了.... 如果恰搭建了邮件服务器,很有可能就自动发到了客户邮箱里,等着炸锅吧.... ...

  7. Git 推送操作

    Jerry 修改了他的最后一次提交的修改操作,他已经准备好将更改.推操作的数据永久存储的 Git 仓库.推操作成功后,其他开发人员可以看到Jerry 的变化. 他执行的git日志命令来查看提交的细节. ...

  8. Sphinx 2.2.11-release reference manual

    1. Introduction 1.1. About 1.2. Sphinx features 1.3. Where to get Sphinx 1.4. License 1.5. Credits 1 ...

  9. Linux下搭建LAMP环境(YUM)

    安装Apache 1.安装Apache yum -y install httpd 2. Apache配置httpd.conf 通过命令 find / -name httpd.conf 找到Apache ...

  10. 缓存Memcached 与 Redis 相同点差异点分析

    memcach简介 Memcache时一个内存对象缓存系统,用于加速动态web应用程序,减轻数据库负载.它可以应对任意多个连接,使用非阻塞的网络I/O,工作机制:在内存中开辟一块空间,然后建立一个ha ...