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. efcore数据库自动生成

    // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. p ...

  2. java的两种同步方式, Synchronized与ReentrantLock的区别

    java在编写多线程程序时,为了保证线程安全,需要对数据同步,经常用到两种同步方式就是Synchronized和重入锁ReentrantLock. 相似点: 这两种同步方式有很多相似之处,它们都是加锁 ...

  3. ECMAScript 6 入门之新的数据类型Symbol

    1.Symbol,一个每次创建都不一样的值 Symbol undefined null Boolean String Number Object let c=Symbol("这是一个Symb ...

  4. 【emWin】例程十四:xbf外置字体

    介绍: 本例将xbf格式文件放到SD卡中,通过读取SD卡中的字库文件在液晶上显示文字.   实验指导书及代码包下载: 链接:http://pan.baidu.com/s/1mhTdYeG 密码:aka ...

  5. Spring MVC异常统一处理的三种方式

    Spring 统一异常处理有 3 种方式,分别为: 使用 @ ExceptionHandler 注解 实现 HandlerExceptionResolver 接口 使用 @controlleradvi ...

  6. js中关于Blob对象的介绍与使用

    js中关于Blob对象的介绍与使用   blob对象介绍 一个 Blob对象表示一个不可变的, 原始数据的类似文件对象.Blob表示的数据不一定是一个JavaScript原生格式 blob对象本质上是 ...

  7. C艹目录

    c++ 学习路线  c++学习路线 c++ 学习目录 c++ 常用数据类型,命名规则, 不常有数据类型 C++复合类型(数组) C艹复合类型(字符串) C++复合类型(结构体) C++ 结构体和枚举 ...

  8. jquery 选择对象随心所欲,遍历数组更是易如反掌

    jquery只要研究总结透彻了,那选择对象就会随心所欲,遍历数组更是易如反掌.选对对象,才能“娶妻生子”,才能有后续的数据处理.呵呵遍历对很关键. 怕只怕,学东西浅尝辄止一知半解.本篇特别研究总结jq ...

  9. Java之CountDownLatch使用

    CountDownLatch,一个同步辅助类,在完成一组正在其他线程中执行的操作之前,它允许一个或多个线程一直等待. 主要方法 public CountDownLatch(int count); pu ...

  10. Spark学习笔记——在远程机器中运行WordCount

    1.通过realy机器登录relay-shell ssh XXX@XXX 2.登录了跳板机之后,连接可以用的机器 XXXX.bj 3.在本地的idea生成好程序的jar包(word-count_2.1 ...