目录
pytorch tensor统计元素个数:
numpy统计矩阵
pytorch tensor统计元素个数:
import torch
import numpy as np
def test():
torch.manual_seed(1)
a = torch.randn(3, 4)
print(a)
print(a.size())
print(*a.size())
print(np.multiply(*a.size()))
test()
结果:
tensor([[ 0.6614, 0.2669, 0.0617, 0.6213],
[-0.4519, -0.1661, -1.5228, 0.3817],
[-1.0276, -0.5631, -0.8923, -0.0583]])
torch.Size([3, 4])
3 4
12
原文链接:https://blog.csdn.net/qq_43678005/article/details/122666046
numpy统计矩阵
import numpy as np
a = np.array([[3, 7, 5], [8, 4, 3], [2, 4, 9]])
print(a.size)
print(a.shape)
结果:文章来源:https://www.toymoban.com/news/detail-703577.html
9
(3, 3)文章来源地址https://www.toymoban.com/news/detail-703577.html
numpy统计元素出现个数:
test1 = np.array([[0, 1, 0], [0, 1, 1], [0, 1, 2]])
x = np.bincount(test1.flatten())
print(x)
到了这里,关于python 统计矩阵元素的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!