日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

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

發(fā)布時間:2025/3/21 编程问答 17 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Py之Numpy:Numpy库中常用函数的简介、应用之详细攻略 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

Py之Numpy:Numpy庫中常用函數(shù)的簡介、應(yīng)用之詳細(xì)攻略

?

目錄

Numpy庫中常用函數(shù)的簡介、應(yīng)用

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


?

?

相關(guān)文章
Py之Numpy:Numpy庫簡介、安裝、使用方法、案例應(yīng)用之詳細(xì)攻略???????
Py之Numpy:Numpy庫中常用函數(shù)的簡介、應(yīng)用之詳細(xì)攻略

Numpy庫中常用函數(shù)的簡介、應(yīng)用

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.

坐標(biāo)向量返回坐標(biāo)矩陣


建立N-D坐標(biāo)陣列,在N-D網(wǎng)格上對N-D標(biāo)量/向量場進行向量化計算,給定一維坐標(biāo)陣列x1, x2,…,xn。

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

參數(shù)
?----------
x1, x2,…, xn: array_like
表示網(wǎng)格坐標(biāo)的一維數(shù)組。
索引:{'xy', 'ij'},可選
Cartesian ('xy',默認(rèn))或矩陣('ij')索引的輸出。
參見注釋了解更多細(xì)節(jié)。

. .versionadded: 1.7.0
稀疏:bool,可選
如果為真,則返回一個稀疏網(wǎng)格以保存內(nèi)存。默認(rèn)是假的。

. .versionadded: 1.7.0
復(fù)制:bool,可選。如果為假,則返回原始數(shù)組的視圖
為了保存記憶。默認(rèn)是正確的。請注意,' ' sparse=False, copy=False ' '將可能返回不相鄰的數(shù)組。此外,廣播數(shù)組中的多個元素可以引用單個內(nèi)存位置。如果需要對數(shù)組進行寫入,請首先進行復(fù)制。

. .versionadded: 1.7.0

返回
?-------
X1, X2,…XN: ndarray
對于向量“x1”,“x2”,…, 'xn'加上length ' ' ' Ni=len(xi) ' ',
返回' ' (N1, N2, N3,…Nn) ' '形數(shù)組如果索引='ij'或' ' (N2, N1, N3,…Nn) ' '形數(shù)組如果索引='xy'與元素' xi '重復(fù)填充矩陣沿第一個維度為' x1 ',第二個為' x2 ',以此類推。

筆記
?-----
這個函數(shù)通過索引關(guān)鍵字參數(shù)支持兩種索引約定。給出字符串'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”索引。區(qū)別如下面的代碼片段所示::

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

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


在1-D和0-D情況下,索引和稀疏關(guān)鍵字沒有影響。。

另請參閱
--------
index_tricks。mgrid:使用索引符號構(gòu)造一個多維“meshgrid”。
index_tricks。ogrid:使用索引符號構(gòu)造一個開放的多維“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)
?


?

?

?

?

?

?

?

總結(jié)

以上是生活随笔為你收集整理的Py之Numpy:Numpy库中常用函数的简介、应用之详细攻略的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。