review. .. ..
from numpy import *
I am doing it.
No recursion
def Fibonacci(x):
if x == 0:
return array([0])
prepre, pre = 0, 1
lst = [0, 1]
for i in range(1, x):
pre, prepre = pre + prepre, pre
lst += [pre]
return array(lst)
With recursion
def Fibonacci_recursive(x):
lst = []
def f(x, lst, is_add=False):
if x > 1:
if is_add:
lst += [f(x-1, lst, True) + f(x-2, lst)]
return f(x-1, lst) + f(x-2, lst)
elif x == 1:
if is_add:
lst += [0, 1]
return 1
else:
if is_add:
lst += [0]
return 0
f(x, lst, True)
return array(lst)
def prime(N):
a = arange(2, N+1)
for i in range(2, N+1):
a = a[where((a <= i) + (a% i != 0))]
return a
I want to come up with a way to implement it without using a for statement.
Recommended Posts