回答此问题可获得 20 贡献值,回答如果被采纳可获得 50 分。
<p>我在python中有一个名为prime\u sieve(N)的函数,如果一个数字不是质数,这个函数会给它赋值0,如果它是质数,这个函数会给它赋值1,这叫做mask。此功能正常工作。问题出在prime_sieve(N)代码下面的第二个函数中,代码是:</p>
<pre><code>import numpy as np
def prime_sieve(N):
nums = np.arange(2, N + 2, 1)
mask = 1 + np.zeroes(N, dtype = int)
for n in nums:
for i in np.arange(2 * n - 2, N, n):
mask[i] = 0
return nums, mask
numbers, mask = prime_sieve(8)
print(numbers) #prints out the actual numbers starting at 2
print(mask) #prints out the 0s and 1s assigned to the values if they are a prime or not.
</code></pre>
<p>我必须在一个名为primes\u list(N)的函数中使用上面提到的函数来打印列表中的素数。素数列表(N)的代码是:</p>
<pre><code>def primes_list(N):
for i in range (0, N, 1):
if mask[i] == 1:
return prime_sieve(numbers[i])
print(primes_list(8))
</code></pre>
<p>我从prime_sieve(N)函数收到的输出是:</p>
<blockquote>
<p>[2, 3, 4, 5, 6, 7, 8, 9]</p>
<p>[1, 1, 0, 1, 0, 1, 0, 0]</p>
</blockquote>
<p>我从primes\u list(N)函数收到的输出是:</p>
<blockquote>
<p>Expected output: [2, 3, 5, 7]</p>
<p>My output: (array([2, 3]), array([1, 1]))</p>
</blockquote>
<p>如有任何建议,我们将不胜感激。你知道吗</p>