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内置函数,指定开始值,终值和步长生成等差数列的一维数组 不包含终值 步长只能是整数,生成整数 ...
随机推荐
- android ndk-build 编译静态库libxx.a 以及Android studio openssl 静态库配置(cmake)
android ndk-build 编译静态库libxx.a 需求场景: 目前有安卓编码好的现在的openssl的两个.a,我们需要调用openssl的函数,并把功能再封装成.a; 这样使用时,在an ...
- open jdk
http://rednaxelafx.iteye.com/blog/1549577 https://www.jianshu.com/p/f98c3acd8df8 http://download.jav ...
- vue中使用some删除list中的数据
在vue中可以使用some方法查找需要删除的所以 this.list.some((item, i) => { if (item.id == id) { this.list.splice(i, 1 ...
- 【PMP】项目的定义和特点
1.定义 项目是为创建独特的产品.服务和成果而进行的的临时性工作. 2.特点 2.1 独特的产品.服务或成果 实现项目目标可能产生一个或多个可交付成果.例如:即便采用相同的材料或者相同的施工单位来建设 ...
- 最简单的社交分享代码,无需注册OpenID
包含新浪微博.QQ空间.人人网一键分享,无需注册各个开放平台的OpenID,简单易用. //分享 function share() { var shareLink = location.href; v ...
- php 实现发送微信模板消息(转)
<?php namespace Org\Weixin; /** * Created by PhpStorm. * User: StandOpen * Date: 15-1-7 * Time: 9 ...
- css中border-radius用法详解
border-radius:由浮点数字和单位标识符组成的长度值.border-top-left-radius --- 左上border-top-right-radius --- 右上border-bo ...
- 【转载】Mysql load data infile用法(万级数据导入,在几秒之内)
https://blog.csdn.net/u014082714/article/details/53173975 http://blog.itpub.net/26506993/viewspace-2 ...
- 如何禁止VS显示“You have mixed tabs and spaces. Fix this?”
如何禁止VS显示“You have mixed tabs and spaces. Fix this?” VS2013 版本的解决方案: Vs2013 IDE下,编辑C++的工程源码,在打开文件的时候 ...
- 2.5 Apache Axis2 快速学习手册之JiBx 构建Web Service
5. 使用JiBX生成服务(通过JIBX 命令将wsdl 生成 services ) 要使用JiBX数据绑定生成和部署服务,请执行以下步骤. 通过在Axis2_HOME / samples / qui ...