NumPy - Fibonacci Series using Binet Formula Last Updated : 03 Jun, 2020 Comments Improve Suggest changes Like Article Like Report All of us are familiar with Fibonacci Series. Each number in the sequence is the sum of the two numbers that precede it. So, the sequence goes: 0, 1, 1, 2, 3, 5, 8, 13, 21, 34...... In this tutorial, we will implement the same using NumPy with the aid of Binet formula. Binet Formula fn = \left [\left (\frac{1 + \sqrt{5}}{2} \right )^{n} - \left (\frac{1 - \sqrt{5}}{2} \right )^{n} \right ]\ast \frac{1}{\sqrt{5}} where, alpha = \left (\frac{1 + \sqrt{5}}{2} \right ), beta = \left (\frac{1 - \sqrt{5} }{2}\right ) ‘n’ is the parameter which relates the first ‘n’ numbers of Fibonacci Series. In the first example we are going to findout first 10 numbers of Fibonacci Series (n = 10), after that we takes the parameter ‘n’ from user and produce the corresponding result. NOTE : We are ignoring the first element(0) of Fibonacci Series Example 1: To find first 10 Fibonacci numbers . Python3 1== import numpy as np # We are creating an array contains n = 10 elements # for getting first 10 Fibonacci numbers a = np.arange(1, 11) lengthA = len(a) # splitting of terms for easiness sqrtFive = np.sqrt(5) alpha = (1 + sqrtFive) / 2 beta = (1 - sqrtFive) / 2 # Implementation of formula # np.rint is used for rounding off to integer Fn = np.rint(((alpha ** a) - (beta ** a)) / (sqrtFive)) print("The first {} numbers of Fibonacci series are {} . ".format(lengthA, Fn)) Output : The first 10 numbers of Fibonacci series are [ 1. 1. 2. 3. 5. 8. 13. 21. 34. 55.] . Example 2 : To find first 'n' Fibonacci numbers .. Python3 1== import numpy as np # We are creating an array contains n elements # for getting first 'n' Fibonacci numbers fNumber = int(input("Enter the value of n + 1'th number : ")) a = np.arange(1, fNumber) length_a = len(a) # splitting of terms for easiness sqrt_five = np.sqrt(5) alpha = (1 + sqrt_five) / 2 beta = (1 - sqrt_five) / 2 # Implementation of formula # np.rint is used for rounding off to integer Fn = np.rint(((alpha ** a) - (beta ** a)) / (sqrt_five)) print("The first {} numbers of Fibonacci series are {} . ".format(length_a, Fn)) Output : # Here user input was 10 Enter the value of n+1'th number :10 The first 9 numbers of Fibonacci series are [ 1. 1. 2. 3. 5. 8. 13. 21. 34.] . Comment More infoAdvertise with us Next Article Sum of numbers in the Kth level of a Fibonacci triangle A amalchandranmv Follow Improve Article Tags : Python Write From Home Python-numpy Python numpy-arrayManipulation Practice Tags : python Similar Reads Sum of numbers in the Kth level of a Fibonacci triangle Given a number K, the task is to find the sum of numbers at the Kth level of the Fibonacci triangle.Examples: Input: K = 3 Output: 10 Explanation: Fibonacci triangle till level 3: 0 1 1 2 3 5 Sum at 3rd level = 2 + 3 + 5 = 10 Input: K = 2 Output: 2 Explanation: Fibonacci triangle till level 3: 0 1 1 6 min read Sum of numbers in the Kth level of a Fibonacci triangle Given a number K, the task is to find the sum of numbers at the Kth level of the Fibonacci triangle.Examples: Input: K = 3 Output: 10 Explanation: Fibonacci triangle till level 3: 0 1 1 2 3 5 Sum at 3rd level = 2 + 3 + 5 = 10 Input: K = 2 Output: 2 Explanation: Fibonacci triangle till level 3: 0 1 1 6 min read Sum of numbers in the Kth level of a Fibonacci triangle Given a number K, the task is to find the sum of numbers at the Kth level of the Fibonacci triangle.Examples: Input: K = 3 Output: 10 Explanation: Fibonacci triangle till level 3: 0 1 1 2 3 5 Sum at 3rd level = 2 + 3 + 5 = 10 Input: K = 2 Output: 2 Explanation: Fibonacci triangle till level 3: 0 1 1 6 min read Find the numbers present at Kth level of a Fibonacci Binary Tree Given a number K, the task is to print the fibonacci numbers present at Kth level of a Fibonacci Binary Tree.Examples: Input: K = 3 Output: 2, 3, 5, 8 Explanation: Fibonacci Binary Tree for 3 levels: 0 / \ 1 1 /\ / \ 2 3 5 8 Numbers present at level 3: 2, 3, 5, 8 Input: K = 2 Output: 1, 1 Explanatio 12 min read Find the numbers present at Kth level of a Fibonacci Binary Tree Given a number K, the task is to print the fibonacci numbers present at Kth level of a Fibonacci Binary Tree.Examples: Input: K = 3 Output: 2, 3, 5, 8 Explanation: Fibonacci Binary Tree for 3 levels: 0 / \ 1 1 /\ / \ 2 3 5 8 Numbers present at level 3: 2, 3, 5, 8 Input: K = 2 Output: 1, 1 Explanatio 12 min read Find the numbers present at Kth level of a Fibonacci Binary Tree Given a number K, the task is to print the fibonacci numbers present at Kth level of a Fibonacci Binary Tree.Examples: Input: K = 3 Output: 2, 3, 5, 8 Explanation: Fibonacci Binary Tree for 3 levels: 0 / \ 1 1 /\ / \ 2 3 5 8 Numbers present at level 3: 2, 3, 5, 8 Input: K = 2 Output: 1, 1 Explanatio 12 min read Like