PyTorch torch.sin - torch.cos

torch
https://pytorch.org/docs/stable/torch.html

torch.sin() - torch.cos()input (Tensor) 都是弧度制数据,不是角度制数据。

  • torch.sin (Python function, in torch.sin)

  • torch.Tensor.sin (Python method, in torch.Tensor.sin)

  • torch.Tensor.sin_ (Python method, in torch.Tensor.sin_)

  • torch.cos (Python function, in torch.cos)

  • torch.Tensor.cos (Python method, in torch.Tensor.cos)

  • torch.Tensor.cos_ (Python method, in torch.Tensor.cos_)

1. torch.sin

https://pytorch.org/docs/stable/generated/torch.sin.html

torch.sin(input, *, out=None) -> Tensor

Returns a new tensor with the sine of the elements of input.
返回一个新的张量 tensor , 其元素是张量 input 元素的正弦。

out i = sin ⁡ ( input i ) \text{out}_{i} = \sin(\text{input}_{i}) outi=sin(inputi)

  • Parameters

input (Tensor) - the input tensor.

  • Keyword Arguments

out (Tensor, optional) - the output tensor.

1.1. Example

(pt-1.4_py-3.6) yongqiang@yongqiang:~$ python
Python 3.6.10 |Anaconda, Inc.| (default, May  8 2020, 02:54:21)
[GCC 7.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import torch
>>> import numpy as np
>>>
>>> data = np.array([0, 1/2.0, 1, 3/2.0, 2])
>>> data
array([0. , 0.5, 1. , 1.5, 2. ])
>>>
>>> data = data * np.pi
>>> data
array([0.        , 1.57079633, 3.14159265, 4.71238898, 6.28318531])
>>>
>>> torch.sin(data)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: sin(): argument 'input' (position 1) must be Tensor, not numpy.ndarray
>>>
>>> torch.sin(torch.Tensor(data))
tensor([ 0.0000e+00,  1.0000e+00, -8.7423e-08, -1.0000e+00,  1.7485e-07])
>>> exit()
(pt-1.4_py-3.6) yongqiang@yongqiang:~$

2. torch.cos

https://pytorch.org/docs/stable/generated/torch.cos.html

Returns a new tensor with the cosine of the elements of input.

out i = cos ⁡ ( input i ) \text{out}_{i} = \cos(\text{input}_{i}) outi=cos(inputi)

  • Parameters

input (Tensor) - the input tensor.

  • Keyword Arguments

out (Tensor, optional) - the output tensor.

2.1. Example

(pt-1.4_py-3.6) yongqiang@yongqiang:~$ python
Python 3.6.10 |Anaconda, Inc.| (default, May  8 2020, 02:54:21)
[GCC 7.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import torch
>>> import numpy as np
>>>
>>> data = np.array([0.0, 1/2.0, 1.0, 3/2.0, 2.0])
>>> data
array([0. , 0.5, 1. , 1.5, 2. ])
>>>
>>> data = data * np.pi
>>> data
array([0.        , 1.57079633, 3.14159265, 4.71238898, 6.28318531])
>>>
>>> torch.cos(torch.Tensor(data))
tensor([ 1.0000e+00, -4.3711e-08, -1.0000e+00,  1.1925e-08,  1.0000e+00])
>>>
>>> torch.sin(torch.Tensor(data))
tensor([ 0.0000e+00,  1.0000e+00, -8.7423e-08, -1.0000e+00,  1.7485e-07])
>>>
>>> exit()
(pt-1.4_py-3.6) yongqiang@yongqiang:~$

References

[1] Yongqiang Cheng, https://yongqiang.blog.csdn.net/

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Yongqiang Cheng

梦想不是浮躁,而是沉淀和积累。

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值