Py之Numpy:Numpy库中常用函数的简介、应用之详细攻略


牛排美丽
牛排美丽 2022-09-19 12:59:10 51718
分类专栏: 资讯

Py之Numpy:Numpy库中常用函数的简介、应用之详细攻略

目录

Numpy库中常用函数的简介、应用

1、X, Y = np.meshgrid(X, Y)


相关文章
Py之Numpy:Numpy库简介、安装、使用方法、案例应用之详细攻略​​​​​​​
Py之Numpy:Numpy库中常用函数的简介、应用之详细攻略

Numpy库中常用函数的简介、应用

1、X, Y = np.meshgrid(X, Y)

meshgrid Found at: numpy.lib.function_base
Return coordinate matrices from coordinate vectors.
    
    Make N-D coordinate arrays for vectorized evaluations of N-D scalar/vector fields over N-D grids, given  one-dimensional coordinate arrays x1, x2,..., xn.
    
    .. versionchanged:: 1.9
    1-D and 0-D cases are allowed.
    
    Parameters
    ----------
    x1, x2,..., xn : array_like
    1-D arrays representing the coordinates of a grid.
    indexing : {'xy', 'ij'}, optional
    Cartesian ('xy', default) or matrix ('ij') indexing of output.
    See Notes for more details.
    
    .. versionadded:: 1.7.0
    sparse : bool, optional
    If True a sparse grid is returned in order to conserve  memory. Default is False.
    
    .. versionadded:: 1.7.0
    copy : bool, optional. If False, a view into the original arrays are returned in 
     order to  conserve memory.  Default is True.  Please note that  ``sparse=False, copy=False`` will likely return noncontiguous arrays.  Furthermore, more than one element of a   broadcast array may refer to a single memory location.  If you need to  write to the arrays, make copies first.
    
    .. versionadded:: 1.7.0
    
    Returns
    -------
    X1, X2,..., XN : ndarray
    For vectors `x1`, `x2`,..., 'xn' with lengths ``Ni=len(xi)`` ,
    return ``(N1, N2, N3,...Nn)`` shaped arrays if indexing='ij'   or ``(N2, N1, N3,...Nn)`` shaped arrays if indexing='xy'  with the elements of `xi` repeated to fill the matrix along  the first dimension for `x1`, the second for `x2` and so on.
    
    Notes
    -----
    This function supports both indexing conventions  through the indexing keyword argument.  Giving the string 'ij' returns a  meshgrid with matrix indexing, while 'xy' returns a meshgrid with   Cartesian indexing.
    In the 2-D case with inputs of length M and N, the  outputs are of shape  (N, M) for 'xy' indexing and (M, N) for 'ij' indexing.  In the   3-D case with inputs of length M, N and P, outputs are of shape   (N, M, P) for   'xy' indexing and (M, N, P) for 'ij' indexing.  The  difference is  illustrated by the following code snippet::
    
    xv, yv = np.meshgrid(x, y, sparse=False, indexing='ij')
    for i in range(nx):
    for j in range(ny):
    treat xv[i,j], yv[i,j]
    
    xv, yv = np.meshgrid(x, y, sparse=False, indexing='xy')
    for i in range(nx):
    for j in range(ny):
    treat xv[j,i], yv[j,i]
    
    In the 1-D and 0-D case, the indexing and sparse  keywords have no effect.
    
    See Also
    --------
    index_tricks.mgrid : Construct a multi-dimensional    "meshgrid" using indexing notation.
    index_tricks.ogrid : Construct an open multi-dimensional   "meshgrid" using indexing notation.

坐标向量返回坐标矩阵


建立N-D坐标阵列,在N-D网格上对N-D标量/向量场进行向量化计算,给定一维坐标阵列x1, x2,…,xn。

. .versionchanged:: 1.9
允许1-D和0-D。

参数
 ----------
x1, x2,…, xn: array_like
表示网格坐标的一维数组。
索引:{'xy', 'ij'},可选
Cartesian ('xy',默认)或矩阵('ij')索引的输出。
参见注释了解更多细节。

. .versionadded: 1.7.0
稀疏:bool,可选
如果为真,则返回一个稀疏网格以保存内存。默认是假的。

. .versionadded: 1.7.0
复制:bool,可选。如果为假,则返回原始数组的视图
为了保存记忆。默认是正确的。请注意,' ' sparse=False, copy=False ' '将可能返回不相邻的数组。此外,广播数组中的多个元素可以引用单个内存位置。如果需要对数组进行写入,请首先进行复制。

. .versionadded: 1.7.0

返回
 -------
X1, X2,…XN: ndarray
对于向量“x1”,“x2”,…, 'xn'加上length ' ' ' Ni=len(xi) ' ',
返回' ' (N1, N2, N3,…Nn) ' '形数组如果索引='ij'或' ' (N2, N1, N3,…Nn) ' '形数组如果索引='xy'与元素' xi '重复填充矩阵沿第一个维度为' x1 ',第二个为' x2 ',以此类推。

笔记
 -----
这个函数通过索引关键字参数支持两种索引约定。给出字符串'ij'返回一个带矩阵索引的meshgrid,而'xy'返回一个带笛卡尔索引的meshgrid。
在输入长度为M和N的二维情况下,输出的形状为(N, M),表示“xy”索引,(M, N)表示“ij”索引。在输入长度为M、N和P的3-D情况下,输出的形状(N、M、P)表示“xy”索引,(M、N、P)表示“ij”索引。区别如下面的代码片段所示::

xv yv = np。meshgrid(x, y, sparse=False, index ='ij')
i在range(nx)内:
j in range(ny):
治疗xv[i,j], yv[i,j]

xv yv = np。meshgrid(x, y, sparse=False, index ='xy')
i在range(nx)内:
j in range(ny):


在1-D和0-D情况下,索引和稀疏关键字没有影响。。

另请参阅
--------
index_tricks。mgrid:使用索引符号构造一个多维“meshgrid”。
index_tricks。ogrid:使用索引符号构造一个开放的多维“meshgrid”。

    Examples
    --------
    >>> nx, ny = (3, 2)
    >>> x = np.linspace(0, 1, nx)
    >>> y = np.linspace(0, 1, ny)
    >>> xv, yv = np.meshgrid(x, y)
    >>> xv
    array([[ 0. ,  0.5,  1. ],
    [ 0. ,  0.5,  1. ]])
    >>> yv
    array([[ 0.,  0.,  0.],
    [ 1.,  1.,  1.]])
    >>> xv, yv = np.meshgrid(x, y, sparse=True)   make 
     sparse output arrays
    >>> xv
    array([[ 0. ,  0.5,  1. ]])
    >>> yv
    array([[ 0.],
    [ 1.]])
    
    `meshgrid` is very useful to evaluate functions on a grid.
    
    >>> x = np.arange(-5, 5, 0.1)
    >>> y = np.arange(-5, 5, 0.1)
    >>> xx, yy = np.meshgrid(x, y, sparse=True)
    >>> z = np.sin(xx**2 + yy**2) / (xx**2 + yy**2)
    >>> h = plt.contourf(x,y,z)
 


 

文章知识点与官方知识档案匹配,可进一步学习相关知识

网站声明:如果转载,请联系本站管理员。否则一切后果自行承担。

本文链接:https://www.xckfsq.com/news/show.html?id=2517
赞同 0
评论 0 条
牛排美丽L0
粉丝 0 发表 11 + 关注 私信
上周热门
如何使用 StarRocks 管理和优化数据湖中的数据?  2944
【软件正版化】软件正版化工作要点  2863
统信UOS试玩黑神话:悟空  2823
信刻光盘安全隔离与信息交换系统  2717
镜舟科技与中启乘数科技达成战略合作,共筑数据服务新生态  1251
grub引导程序无法找到指定设备和分区  1217
华为全联接大会2024丨软通动力分论坛精彩议程抢先看!  163
点击报名 | 京东2025校招进校行程预告  162
2024海洋能源产业融合发展论坛暨博览会同期活动-海洋能源与数字化智能化论坛成功举办  160
华为纯血鸿蒙正式版9月底见!但Mate 70的内情还得接着挖...  157
本周热议
我的信创开放社区兼职赚钱历程 40
今天你签到了吗? 27
信创开放社区邀请他人注册的具体步骤如下 15
如何玩转信创开放社区—从小白进阶到专家 15
方德桌面操作系统 14
我有15积分有什么用? 13
用抖音玩法闯信创开放社区——用平台宣传企业产品服务 13
如何让你先人一步获得悬赏问题信息?(创作者必看) 12
2024中国信创产业发展大会暨中国信息科技创新与应用博览会 9
中央国家机关政府采购中心:应当将CPU、操作系统符合安全可靠测评要求纳入采购需求 8

加入交流群

请使用微信扫一扫!