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内置函数,指定开始值,终值和步长生成等差数列的一维数组 不包含终值 步长只能是整数,生成整数 ...
随机推荐
- 不依赖三方库从图像数据中获取宽高-gif、bmp、png、jepg
int extract_pic_info(const BYTE *pic, const uint32_t size, int &width, int &height) { ; widt ...
- zabbix用户管理
zabbix用户管理,主要包括用户增删改查.用户报警媒介管理.用户权限管理. 安装完zabbix后,已经自带了两个用户Admin和Guests 超级管理员默认账号:Admin,密码:zabbix,这是 ...
- 使用yocs_velocity_smoother对机器人速度进行限制
yocs_velocity_smoother是一个速度.加速度限制器,用来防止robot navigation的速度/转速过快,加速度/快减速过大.Bound incoming velocity me ...
- R语言手册
在R的官方教程里是这么给R下注解的:一个数据分析和图形显示的程序设计环境(A system for data analysis and visualization which is built bas ...
- C++赋值兼容原则
C++赋值兼容原则(派生类对象是基类对象,反之不成立) –基类指针强制转换成派生类指针 –派生类中重定义基类成员(同名覆盖) 假设, 一个基类 "普通人", 一个派生类 " ...
- Windows 不能复制文件到远程服务器的解决办法
1. 开始 -> 运行->浏览->C:\Windows\System32\rdpclip.exe->打开. 2. 打开资源管理器的进程可以看到 rdp复制粘贴正在运行,即可.
- [svc]linux下网桥-docker网桥
网桥和交换机 2口交换机=网桥 交换机: 工作在数据链路层,根据源mac学习(控制层),目的mac转发(数据层). linux的网卡 vmware workstation中的桥接 参考: http:/ ...
- [k8s]svc里知识点小结
svc里面涉及到的概念较多一些,总结如下
- vue cli 项目的提交
前提: 配置git.以及git的ssh key信息 假设已经都安装好了,此处我用vue项目为例,因为vue-cli已经默认为我生成了ignore文件 在项目目录 初始化本地仓库,会创建一个.git目录 ...
- 两次内存断点法寻找OEP
所谓“两次内存断点法寻找OEP”,按照<加密与解密*第三版>上的解释来说,就是这样的.一般的外壳会依次对.text..rdata..data..rsrc区块进行解压(解密)处理,所以,可以 ...