擅长:python、mysql、java
<p>如果您在python2.x下运行这个程序,那么您将丢失<code>2*alpha/180*np.pi</code>语句的信息(尽管python3.x应该可以工作)。你知道吗</p>
<p>这些操作按优先顺序(在本例中是从左到右)进行计算,从而</p>
<pre><code>((2 * alpha) / 180) * ni.pi
=> (90 / 180) * ni.pi # integer division truncates this to 0
=> 0 * ni.pi
</code></pre>
<p>您需要手动转换为浮点数:</p>
<pre><code>np.sin(2.0*alpha/180*np.pi) # the floating point 2.0 will promote alpha to float for the multiply
</code></pre>
<p>或者</p>
<pre><code>np.sin(2*float(alpha)/180*np.pi) # explicit, very clear
</code></pre>
<p>或者</p>
<pre><code>alpha = 45.0 # this is a little dangerous as you might change the angle in the future and forget to make it a float again
</code></pre>