Python PyTorch is_tensor()用法及代码示例

参考Python PyTorch is_tensor()用法及代码示例 - 云+社区 - 腾讯云

PyTorch torch.is_tensor()如果传递的对象是PyTorch张量,则方法返回True。

用法:

torch.is_tensor(object) 

参数

  • object:这是要测试的输入张量。

返回:它返回True或False。

让我们借助几个示例来了解这个概念:
范例1:
 

# Importing the PyTorch library  
import torch  
    
# A constant tensor of size n 
a = torch.FloatTensor([1, 4, 6, 9]) 
print(a) 
  
# Applying the is_tensor function and  
# storing the result in 'out' 
out = torch.is_tensor(a) 
print(out)

输出:

1
4
6
9
[torch.FloatTensor of size 4]
True

范例2:

# Importing the PyTorch library  
import torch  
    
# A constant tensor of size n 
a = torch.randn(4, 6) 
print(a) 
  
# Applying the is_tensor function and  
# storing the result in 'out' 
out = torch.is_tensor(a) 
print(out)

输出:

 0.7491 -1.5987 -0.9733  0.0436 -0.3093  2.0007
 0.5679 -0.0092 -0.2573  0.9173  2.9849 -2.0159
-1.9215 -0.9131 -0.8244  0.4160 -0.3855  0.7033
 1.7367 -1.1454 -1.4369 -0.9856 -0.9076  0.6267
[torch.FloatTensor of size 4x6]
True

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Wanderer001

ROIAlign原理

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值