from_numpy
函数原型:
torch.from_numpy(ndarray) → Tensor
从numpy.ndarray对象中创建一个Tensor。
注意返回的tensor和ndarray共享同一块内存。对tensor的修改会影响ndarray中的数据,反过来也是一样。这个返回的tensor是resizable。
目前这个函数接受数据类型为numpy.float64、numpy.float32、numpy.float16、numpy.complex64、numpy.complex128、numpy.int64、numpy.int32、numpy.int16、numpy.int8、numpy.uint8以及numpy.bool的ndarray
使用示例:
>>> a = numpy.array([1, 2, 3])
>>> t = torch.from_numpy(a)
>>> t
tensor([ 1,
2,
3])
>>> t[0] = -1
>>> a
array([-1,
2,
3])
sqrt
函数原型:
torch.sqrt(input, *, out=None) → Tensor
这个函数返回输入input的开方:
o u t i = i n p u t i out_i=sqrt{input_i} outi=inputi
参数:
- input (Tensor):输入tensor
keyword参数:
- out (Tensor, optional):输出tensor
使用示例:
>>> a = torch.randn(4)
>>> a
tensor([-2.0755,
1.0226,
0.0831,
0.4806])
>>> torch.sqrt(a)
tensor([
nan,
1.0112,
0.2883,
0.6933])
最后
以上就是热心机器猫最近收集整理的关于pytorch模块函数API介绍的全部内容,更多相关pytorch模块函数API介绍内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复