當前位置: 首頁>>編程示例 >>用法及示例精選 >>正文


Python PyTorch floor()用法及代碼示例

PyTorch torch.floor()方法返回一個新的張量,該張量是輸入元素的下限,小於或等於每個元素的最大整數。
floor method

用法: torch.floor(input, out=None)

參數

  • input:這是輸入張量。
  • out:輸出張量。

返回:它返回張量。

讓我們借助幾個示例來了解這個概念:
範例1:

# Importing the PyTorch library  
import torch  
    
# A constant tensor of size n 
a = torch.FloatTensor([1.5, 4.2, 6.7, 3.9]) 
print(a) 
  
# Applying the floor function and  
# storing the result in 'out' 
out = torch.floor(a) 
print(out)

輸出:

 1.5000
 4.2000
 6.7000
 3.9000
[torch.FloatTensor of size 4]

 1
 4
 6
 3
[torch.FloatTensor of size 4]

範例2:

# Importing the PyTorch library  
import torch  
    
# A constant tensor of size n 
a = torch.FloatTensor([1.59, 4.5999, 6.78, 3.99999]) 
print(a) 
  
# Applying the floor function and  
# storing the result in 'out' 
out = torch.floor(a) 
print(out)

輸出:

1.5900
 4.5999
 6.7800
 4.0000
[torch.FloatTensor of size 4]

 1
 4
 6
 3
[torch.FloatTensor of size 4]

相關用法


注:本文由純淨天空篩選整理自PranchalKatiyar大神的英文原創作品 Python – PyTorch floor() method。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。