maxframe.tensor.cos#

maxframe.tensor.cos(x, out=None, where=None, **kwargs)[源代码]#

逐元素计算余弦值。

参数:
  • x (array_like) -- 以弧度为单位的输入张量。

  • out (Tensor, None, or tuple of Tensor and None, optional) -- 用于存储结果的位置。如果提供,其形状必须可以广播到输入。如果未提供或为 None,则返回一个新分配的数组。元组(只能作为关键字参数)的长度必须等于输出的数量。

  • where (array_like, optional) -- 值为 True 表示在该位置计算 ufunc,值为 False 表示保留输出中的值不变。

  • **kwargs

返回:

y -- 对应的余弦值。

返回类型:

Tensor

备注

如果提供了 out,函数会将结果写入其中,并返回对 out 的引用。(参见示例)

引用

M. Abramowitz and I. A. Stegun, Handbook of Mathematical Functions. New York, NY: Dover, 1972.

示例

>>> import maxframe.tensor as mt
>>> mt.cos(mt.array([0, mt.pi/2, mt.pi])).execute()
array([  1.00000000e+00,   6.12303177e-17,  -1.00000000e+00])
>>>
>>> # Example of providing the optional output parameter
>>> out1 = mt.empty(1)
>>> out2 = mt.cos([0.1], out1)
>>> out2 is out1
True
>>>
>>> # Example of ValueError due to provision of shape mis-matched `out`
>>> mt.cos(mt.zeros((3,3)),mt.zeros((2,2)))
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ValueError: operators could not be broadcast together with shapes (3,3) (2,2)