The*_*tor 4 python arrays math trigonometry numpy
我有a1242个数字命名的数组。我需要获取Python中所有数字的余弦值。
当我使用时:cos_ra = math.cos(a)我收到一条错误消息:
TypeError:只有length-1数组可以转换为Python标量
我怎么解决这个问题??
提前致谢
问题是您在numpy.math.cos这里使用,期望您通过标量。使用numpy.cos,如果你想申请cos一个迭代。
In [30]: import numpy as np
In [31]: np.cos(np.array([1, 2, 3]))
Out[31]: array([ 0.54030231, -0.41614684, -0.9899925 ])
Run Code Online (Sandbox Code Playgroud)
错误:
In [32]: np.math.cos(np.array([1, 2, 3]))
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-32-8ce0f3c0df04> in <module>()
----> 1 np.math.cos(np.array([1, 2, 3]))
TypeError: only length-1 arrays can be converted to Python scalars
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
13011 次 |
| 最近记录: |