我有以下Python代码,用于计算第一个n
Euler Totient函数值:
import numpy as np
def euler_totients(n):
phi = np.arange(n+1)
it = np.nditer(phi, flags=['f_index'])
for i in it:
if i == it.index and it.index > 1:
for j in range(it.index, n+1, it.index):
phi[j] -= phi[j] / it.index
return phi
我想将numpy.nditer
用于内部循环,但它似乎不允许指定内部循环所需的起点或步长。官方的documentation for ^{itershape
参数的简要描述(听起来很有希望),但它有点模糊,没有包含示例
那么,有没有一种方法可以指定numpy.nditer
的起点和步长,如果有,如何指定
纯python版本更快:
相关问题 更多 >
编程相关推荐