资讯

精准传达 • 有效沟通

从品牌网站建设到网络营销策划,从策略到执行的一站式服务

Python中is_tensor()方法如何使用

这篇文章将为大家详细讲解有关Python中is_tensor()方法如何使用,文章内容质量较高,因此小编分享给大家做个参考,希望大家阅读完这篇文章后对相关知识有一定的了解。

创新互联建站是专业的柘城网站建设公司,柘城接单;提供成都网站制作、成都做网站,网页设计,网站设计,建网站,PHP网站建设等专业做网站服务;采用PHP框架,可快速的进行柘城网站开发网页制作和功能扩展;专业做搜索引擎喜爱的网站,专业的做网站团队,希望更多企业前来合作!

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

关于Python中is_tensor()方法如何使用就分享到这里了,希望以上内容可以对大家有一定的帮助,可以学到更多知识。如果觉得文章不错,可以把它分享出去让更多的人看到。


文章标题:Python中is_tensor()方法如何使用
链接地址:http://cdkjz.cn/article/gdoisg.html
多年建站经验

多一份参考,总有益处

联系快上网,免费获得专属《策划方案》及报价

咨询相关问题或预约面谈,可以通过以下方式与我们联系

大客户专线   成都:13518219792   座机:028-86922220