請我喝杯咖啡☕
*備忘錄:
- 我的帖子解釋了 add()。
- 我的帖子解釋了 mul()。
- 我的帖子解釋了 div()。
- 我的帖子解釋了餘數()。
- 我的帖子解釋了 fmod()。
sub() 可以與零個或多個元素或標量的0D 或多個D 張量中的兩個或零個或多個元素的0D 或多個D 張量與一個標量進行減法,得到為零的0D 或多個D 張量或更多元素,如下所示:
*備忘錄:
- sub() 可以與 torch 或張量一起使用。
- 第一個參數(輸入)與 torch(類型:int、float 或 complex 的張量或標量)或使用張量(類型:int、float 或 complex 的張量)(必需)。
- 帶有 torch 的第二個參數或帶有張量的第一個參數是其他(必需類型:張量或 int、float 或complex 標量)。
- 帶有 torch 的第三個參數或帶有張量的第二個參數是 alpha(可選-預設:1-類型:張量或整數、浮點或複數標量)。 *other 乘以 alpha(輸入或張量 -(otherxalpha))。
- torch 存在 out 參數(可選-預設:無-型別:張量):
*備註:
- 必須使用 out=。
- 我的貼文解釋了論點。
- minus() 是 sub() 的別名。
import torch tensor1 = torch.tensor([9, 7, 6]) tensor2 = torch.tensor([[4, -4, 3], [-2, 5, -5]]) torch.sub(input=tensor1, other=tensor2) tensor1.sub(other=tensor2) torch.sub(input=tensor1, other=tensor2, alpha=1) torch.sub(input=tensor1, other=tensor2, alpha=torch.tensor(1)) # tensor([[5, 11, 3], [11, 2, 11]]) torch.sub(input=tensor1, other=tensor2, alpha=0) torch.sub(input=tensor1, other=tensor2, alpha=torch.tensor(0)) # tensor([[9, 7, 6], [9, 7, 6]]) torch.sub(input=tensor1, other=tensor2, alpha=2) torch.sub(input=tensor1, other=tensor2, alpha=torch.tensor(2)) # tensor([[1, 15, 0], [13, -3, 16]]) torch.sub(input=tensor1, other=tensor2, alpha=-1) torch.sub(input=tensor1, other=tensor2, alpha=torch.tensor(-1)) # tensor([[13, 3, 9], [7, 12, 1]]) torch.sub(input=tensor1, other=tensor2, alpha=-2) torch.sub(input=tensor1, other=tensor2, alpha=torch.tensor(-2)) # tensor([[17, -1, 12], [5, 17, -4]]) torch.sub(input=9, other=tensor2) torch.sub(input=9, other=tensor2, alpha=1) torch.sub(input=9, other=tensor2, alpha=torch.tensor(1)) # tensor([[5, 13, 6], [11, 4, 14]]) torch.sub(input=tensor1, other=4) torch.sub(input=tensor1, other=4, alpha=1) torch.sub(input=tensor1, other=4, alpha=torch.tensor(1)) # tensor([5, 3, 2]) torch.sub(input=9, other=4) torch.sub(input=9, other=4, alpha=1) torch.sub(input=9, other=4, alpha=torch.tensor(1)) # tensor(5) tensor1 = torch.tensor([9., 7., 6.]) tensor2 = torch.tensor([[4., -4., 3.], [-2., 5., -5.]]) torch.sub(input=tensor1, other=tensor2) torch.sub(input=tensor1, other=tensor2, alpha=1.) torch.sub(input=tensor1, other=tensor2, alpha=torch.tensor(1.)) # tensor([[5., 11., 3.], [11., 2., 11.]]) torch.sub(input=9., other=tensor2) torch.sub(input=9., other=tensor2, alpha=1.) torch.sub(input=9., other=tensor2, alpha=torch.tensor(1.)) # tensor([[5., 13., 6.], [11., 4., 14.]]) torch.sub(input=tensor1, other=4) torch.sub(input=tensor1, other=4, alpha=1.) torch.sub(input=tensor1, other=4, alpha=torch.tensor(1.)) # tensor([5., 3., 2.]) torch.sub(input=9., other=4) torch.sub(input=9., other=4, alpha=1.) torch.sub(input=9., other=4, alpha=torch.tensor(1.)) # tensor(5.) tensor1 = torch.tensor([9.+0.j, 7.+0.j, 6.+0.j]) tensor2 = torch.tensor([[4.+0.j, -4.+0.j, 3.+0.j], [-2.+0.j, 5.+0.j, -5.+0.j]]) torch.sub(input=tensor1, other=tensor2) torch.sub(input=tensor1, other=tensor2, alpha=1.+0.j) torch.sub(input=tensor1, other=tensor2, alpha=torch.tensor(1.+0.j)) # tensor([[5.+0.j, 11.+0.j, 3.+0.j], # [11.+0.j, 2.+0.j, 11.+0.j]]) torch.sub(input=9.+0.j, other=tensor2) torch.sub(input=9.+0.j, other=tensor2, alpha=1.+0.j) torch.sub(input=9.+0.j, other=tensor2, alpha=torch.tensor(1.+0.j)) # tensor([[5.+0.j, 13.+0.j, 6.+0.j], # [11.+0.j, 4.+0.j, 14.+0.j]]) torch.sub(input=tensor1, other=4.+0.j) torch.sub(input=tensor1, other=4.+0.j, alpha=1.+0.j) torch.sub(input=tensor1, other=4.+0.j, alpha=torch.tensor(1.+0.j)) # tensor([5.+0.j, 3.+0.j, 2.+0.j]) torch.sub(input=9.+0.j, other=4.+0.j) torch.sub(input=9.+0.j, other=4.+0.j, alpha=1.+0.j) torch.sub(input=9.+0.j, other=4.+0.j, alpha=torch.tensor(1.+0.j)) # tensor(5.+0.j)
以上是PyTorch 中的子項目的詳細內容。更多資訊請關注PHP中文網其他相關文章!

SlicingaPythonlistisdoneusingthesyntaxlist[start:stop:step].Here'showitworks:1)Startistheindexofthefirstelementtoinclude.2)Stopistheindexofthefirstelementtoexclude.3)Stepistheincrementbetweenelements.It'susefulforextractingportionsoflistsandcanuseneg

numpyallowsforvariousoperationsonArrays:1)basicarithmeticlikeaddition,減法,乘法和division; 2)evationAperationssuchasmatrixmultiplication; 3)element-wiseOperations wiseOperationswithOutexpliitloops; 4)

Arresinpython,尤其是Throughnumpyandpandas,weessentialFordataAnalysis,offeringSpeedAndeffied.1)NumpyArseNable efflaysenable efficefliceHandlingAtaSetSetSetSetSetSetSetSetSetSetSetsetSetSetSetSetsopplexoperationslikemovingaverages.2)

列表sandnumpyArraysInpythonHavedIfferentMemoryfootprints:listSaremoreFlexibleButlessMemory-效率,而alenumpyArraySareSareOptimizedFornumericalData.1)listsStorReereReereReereReereFerenceStoObjects,with withOverHeadeBheadaroundAroundaround64byty64-bitsysysysysysysysysyssyssyssyssysssyssys2)

toensurepythonscriptsbehavecorrectlyacrycrosdevelvermations,分期和生產,USETHESTERTATE:1)Environment varriablesForsimplesettings,2)configurationfilesfilesForcomPlexSetups,3)dynamiCofforComplexSetups,dynamiqualloadingForaptaptibality.eachmethodoffersuniquebeneiquebeneqeniquebenefitsandrefitsandrequiresandrequiresandrequiresca

Python列表切片的基本語法是list[start:stop:step]。 1.start是包含的第一個元素索引,2.stop是排除的第一個元素索引,3.step決定元素之間的步長。切片不僅用於提取數據,還可以修改和反轉列表。

ListSoutPerformarRaysin:1)DynamicsizicsizingandFrequentInsertions/刪除,2)儲存的二聚體和3)MemoryFeliceFiceForceforseforsparsedata,butmayhaveslightperformancecostsinclentoperations。

toConvertapythonarraytoalist,usEthelist()constructororageneratorexpression.1)intimpthearraymoduleandcreateanArray.2)USELIST(ARR)或[XFORXINARR] to ConconverTittoalist,請考慮performorefformanceandmemoryfformanceandmemoryfformienceforlargedAtasetset。


熱AI工具

Undresser.AI Undress
人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover
用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool
免費脫衣圖片

Clothoff.io
AI脫衣器

Video Face Swap
使用我們完全免費的人工智慧換臉工具,輕鬆在任何影片中換臉!

熱門文章

熱工具

SublimeText3漢化版
中文版,非常好用

SAP NetWeaver Server Adapter for Eclipse
將Eclipse與SAP NetWeaver應用伺服器整合。

SublimeText3 英文版
推薦:為Win版本,支援程式碼提示!

mPDF
mPDF是一個PHP庫,可以從UTF-8編碼的HTML產生PDF檔案。原作者Ian Back編寫mPDF以從他的網站上「即時」輸出PDF文件,並處理不同的語言。與原始腳本如HTML2FPDF相比,它的速度較慢,並且在使用Unicode字體時產生的檔案較大,但支援CSS樣式等,並進行了大量增強。支援幾乎所有語言,包括RTL(阿拉伯語和希伯來語)和CJK(中日韓)。支援嵌套的區塊級元素(如P、DIV),

SecLists
SecLists是最終安全測試人員的伙伴。它是一個包含各種類型清單的集合,這些清單在安全評估過程中經常使用,而且都在一個地方。 SecLists透過方便地提供安全測試人員可能需要的所有列表,幫助提高安全測試的效率和生產力。清單類型包括使用者名稱、密碼、URL、模糊測試有效載荷、敏感資料模式、Web shell等等。測試人員只需將此儲存庫拉到新的測試機上,他就可以存取所需的每種類型的清單。