Skip to content
geeksforgeeks
  • Tutorials
    • Python
    • Java
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
    • Practice Coding Problems
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Numpy exercise
  • pandas
  • Matplotlib
  • Data visulisation
  • EDA
  • Machin Learning
  • Deep Learning
  • NLP
  • Data science
  • ML Tutorial
  • Computer Vision
  • ML project
Open In App
Next Article:
NumPy - Fibonacci Series using Binet Formula
Next article icon

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.] . 

Next Article
NumPy - Fibonacci Series using Binet Formula

A

amalchandranmv
Improve
Article Tags :
  • Python
  • Write From Home
  • Python-numpy
  • Python numpy-arrayManipulation
Practice Tags :
  • python

Similar Reads

    Nth multiple of a number in Fibonacci Series in Python
    Our task is to find the nth multiple of a number in the Fibonacci series which involves identifying Fibonacci numbers that are exactly divisible by a given number m. This means we will check each Fibonacci number one by one and select only those that are multiples of m. Once we find the nth such num
    4 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
    Python | sympy.fibonacci() method
    With the help of sympy.fibonacci() method, we can find the Fibonacci number and Fibonacci polynomial in SymPy. fibonacci(n) - The Fibonacci numbers are the integer sequence defined by the initial terms F_0 = 0 , F_1 = 1 and the two-term recurrence relation F_n = F_{n-1} + F_{n-2} . Syntax: fibonacci
    2 min read
    How to Check if a Given Number is Fibonacci number - Python
    Fibonacci numbers are part of a famous sequence where each number is the sum of the two preceding ones, i.e. F(n) = F(n-1) + F(n-2). The sequence starts as:0, 1, 1, 2, 3, 5, 8, 13, 21, 34, ...Notice that every number is equal to the sum of its previous 2 numbers. In this article, we will learn how t
    2 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences