Fibonacci and prime implementations (python)

review. .. ..

from numpy import *

I am doing it.

Fibonacci number

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)

Prime number

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

Fibonacci and prime implementations (python)
Python fast fibonacci
Prime number enumeration and primality test in Python
[python] Compress and decompress
Python and numpy tips
Prime numbers and divisors
[Python] pip and wheel
Fibonacci sequence using Python
Batch design and python
Python iterators and generators
Ruby, Python and map
python input and output
Python and Ruby split
Python3, venv and Ansible
Prime numbers in Python
Prime number 2 in Python
Python asyncio and ContextVar
Benchmark for C, Java and Python with prime factorization
Receives and outputs standard output of Python 2 and Python 3> C implementations
Generate Fibonacci numbers with Python closures, iterators, and generators
Programming with Python and Tkinter
Encryption and decryption with Python
Python: Class and instance variables
[Python 3] Prime factorization in 14 lines
3-3, Python strings and character codes
Python 2 series and 3 series (Anaconda edition)
Python and hardware-Using RS232C with Python-
Python on Ruby and angry Ruby on Python
Python indentation and string format
Python real division (/) and integer division (//)
Install Python and Flask (Windows 10)
About python objects and classes
About Python variables and objects
Apache mod_auth_tkt and Python AuthTkt
Å (Ongustromu) and NFC @ Python
Python shallow copy and deep copy
Python and ruby slice memo
Determine prime numbers with python
Python installation and basic grammar
I compared Java and Python!
Python shallow and deep copy
About Python datetime and timezone
Install Python 3.7 and Django 3.0 (CentOS)
Python environment construction and TensorFlow
Python class variables and instance variables
Ruby and Python syntax ~ branch ~
[Python] Python and security-① What is Python?
Stack and Queue in Python
python metaclass and sqlalchemy declareative
Python basics: conditions and iterations
Solving with Ruby and Python AtCoder ARC067 C Prime Factorization
Python bitwise operator and OR
Python debug and test module
Python list and tuples and commas
Memoization recursion and dynamic programming known by Python Fibonacci sequence
Python variables and object IDs
Python list comprehensions and generators
About Python and regular expressions
python with pyenv and venv
Unittest and CI in Python
Maxout description and implementation (Python)