我有以下 numpy 陣列:
x=np.linspace(1,10,20)
我嘗試在其上應用數學函式:
y=x**3-4*x**2 30
它按預期作業并生成了一個陣列。但是,當我嘗試使用一個math函式時,它似乎不起作用:
y=math.sin(x)
TypeError: only size-1 arrays can be converted to Python scalars
如何有效地在陣列上應用函式(無需使用回圈)?
uj5u.com熱心網友回復:
您可以使用 numpy 等效項。numpy.sin:
y = np.sin(x)
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/515355.html
標籤:Python麻木的数学
上一篇:如何從角點計算x/y旋轉?
