最新下载
热门教程
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
pytorch中numel函数用法代码示例
时间:2022-06-25 02:01:47 编辑:袖梨 来源:一聚教程网
本篇文章小编给大家分享一下pytorch中numel函数用法代码示例,文章代码介绍的很详细,小编觉得挺不错的,现在分享给大家供大家参考,有需要的小伙伴们可以来看看。
获取tensor中一共包含多少个元素
import torch x = torch.randn(3,3) print("number elements of x is ",x.numel()) y = torch.randn(3,10,5) print("number elements of y is ",y.numel())
输出:
number elements of x is 9
number elements of y is 150
27和150分别位x和y中各有多少个元素或变量
补充:pytorch获取张量元素个数numel()的用法
numel就是"number of elements"的简写。
numel()可以直接返回int类型的元素个数
import torch a = torch.randn(1, 2, 3, 4) b = a.numel() print(type(b)) # int print(b) # 24
通过numel()函数,我们可以迅速查看一个张量到底又多少元素。
相关文章
- 四海兄弟故乡人物边缘模糊怎么办 人物边缘模糊解决方法 08-21
- 四海兄弟故乡神秘狐狸06怎么找 神秘狐狸06位置介绍 08-21
- 四海兄弟故乡神秘狐狸05怎么找 神秘狐狸05位置说明 08-21
- 诛仙2四海战歌奇遇怎么做 四海战歌东海奇遇收集 08-21
- 四海兄弟故乡神秘狐狸04怎么找 神秘狐狸04位置一览 08-21
- 四海兄弟故乡城市有多少 城市地点背景介绍 08-21