mars.tensor.cos#
- mars.tensor.cos(x, out=None, where=None, **kwargs)[来源]#
逐元素余弦。
- Parameters
x (array_like) – 输入张量(弧度)。
out (张量, None, 或 元组 由 张量和 None 组成,可选) – 结果存储的位置。如果提供,必须具有与输入广播到的形状相同。如果未提供或 None,则返回新分配的数组。元组(仅作为关键字参数可能)必须具有与输出数量相等的长度。
where (array_like, 可选) – 值为 True 表示在该位置计算 ufunc,值为 False 表示保持输出中的该值不变。
**kwargs –
- Returns
y – 对应的余弦值。
- Return type
张量
备注
如果 out 被提供,函数将结果写入其中,并返回对 out 的引用。 (参见示例)
参考文献
M. Abramowitz 和 I. A. Stegun, 数学函数手册。纽约, NY: Dover, 1972.
示例
>>> import mars.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: operands could not be broadcast together with shapes (3,3) (2,2)