本文整理汇总了Python中PyTorch.asTensor方法的典型用法代码示例。如果您正苦于以下问题:Python PyTorch.asTensor方法的具体用法?Python PyTorch.asTensor怎么用?Python PyTorch.asTensor使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PyTorch
的用法示例。
在下文中一共展示了PyTorch.asTensor方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: print
# 需要导入模块: import PyTorch [as 别名]
# 或者: from PyTorch import asTensor [as 别名]
from __future__ import print_function
import PyTorch
import array
import numpy
A = numpy.random.rand(6).reshape(3,2).astype(numpy.float32)
B = numpy.random.rand(8).reshape(2,4).astype(numpy.float32)
C = A.dot(B)
print('C', C)
print('calling .asTensor...')
tensorA = PyTorch.asTensor(A)
tensorB = PyTorch.asTensor(B)
print(' ... asTensor called')
print('tensorA', tensorA)
tensorA.set2d(1, 1, 56.4)
tensorA.set2d(2, 0, 76.5)
print('tensorA', tensorA)
print('A', A)
tensorA += 5
print('tensorA', tensorA)
print('A', A)
tensorA2 = tensorA + 7
print('tensorA2', tensorA2)
print('tensorA', tensorA)
示例2:
# 需要导入模块: import PyTorch [as 别名]
# 或者: from PyTorch import asTensor [as 别名]
from __future__ import print_function
import PyTorch
import array
import numpy
import sys
A = numpy.random.rand(6).reshape(2,3).astype(numpy.float32)
tensorA = PyTorch.asTensor(A)
nn = PyTorch.Nn()
linear = nn.Linear(3, 8)
output = linear.updateOutput(tensorA)
print('output', output)
print('weight', linear.weight)
#dataset = nn.Dataset()
#criterion = nn.MSECriterion()
#trainer = nn.StochasticGradient(linear, criterion)
sys.path.append('thirdparty/python-mnist')
from mnist import MNIST
mlp = nn.Sequential()
mlp.add(nn.Linear(784, 10))
mlp.add(nn.LogSoftMax())
criterion = nn.ClassNLLCriterion()
learningRate = 0.0001