回答此问题可获得 20 贡献值,回答如果被采纳可获得 50 分。
<p>我在写一个程序,我想用一个大数(<code>1.692287392646066e+41</code>)乘以一个数组中的每个数,我这样做:</p>
<pre><code>x = array([ 16, 18, 19, 15, 27, 26, 13, 34, 38, 36, 43, 42, 48,
50, 55, 57, 70, 67, 65, 85, 99, 94, 90, 112, 126, 130,
142, 120])
weight = 1.692287392646066e+41
x[:] = [i*weight for i in x]
</code></pre>
<p>但后来我收到了错误“overflowerr:Python int太大,无法转换为C long”。奇怪的是,将for循环外的数字相乘似乎有效:</p>
^{pr2}$
<p>我的问题是,既然我事先不知道数组有多长,有没有什么方法可以在for循环中执行此操作?(我知道它有一排。)</p>