How to compute derivative using Numpy? Last Updated : 23 Jul, 2025 Comments Improve Suggest changes 4 Likes Like Report In this article, we will learn how to compute derivatives using NumPy. Generally, NumPy does not provide any robust function to compute the derivatives of different polynomials. However, NumPy can compute the special cases of one-dimensional polynomials using the functions numpy.poly1d() and deriv(). Functions used:poly1d(): It helps to define a polynomial expression or a function.deriv(): Calculates and gives us the derivative expressionApproach:At first, we need to define a polynomial function using the numpy.poly1d() function.Then we need to derive the derivative expression using the derive() function.At last, we can give the required value to x to calculate the derivative numerically. Below are some examples where we compute the derivative of some expressions using NumPy. Here we are taking the expression in variable 'var' and differentiating it with respect to 'x'. Example 1: Python3 import numpy as np # defining polynomial function var = np.poly1d([1, 0, 1]) print("Polynomial function, f(x):\n", var) # calculating the derivative derivative = var.deriv() print("Derivative, f(x)'=", derivative) # calculates the derivative of after # given value of x print("When x=5 f(x)'=", derivative(5)) Output: Example 2: Python3 import numpy as np # defining polynomial function var = np.poly1d([4, 9, 5, 1, 6]) print("Polynomial function, f(x):\n", var) # calculating the derivative derivative = var.deriv() print("Derivative, f(x)'=\n", derivative) # calculates the derivative of after # given value of x print("When x=3 f(x)'=", derivative(3)) Output: Example 3: Python3 import numpy as np # defining polynomial function var = np.poly1d([5, 4, 9, 5, 1, 6]) print("Polynomial function:\n", var) # calculating the derivative derivative = var.deriv() print("Derivative, f(x)'=\n", derivative) # calculates the derivative of after # given value of x print("When x=2 f(x)'=", derivative(0.2)) Output: To calculate double derivative we can simply use the deriv() function twice. Example 4: Python3 import numpy as np # defining polynomial function var = np.poly1d([3, 5, 4, 9, 5, 1, 6]) print("Polynomial function:\n", var) # calculating the derivative derivative = var.deriv() print("Derivative, f(x)'=\n", derivative) # calculates the derivative of after # given value of x print("When x=1 f(x)'=", derivative(1)) derivative1 = derivative.deriv() print("\n\nDerivative, f(x)''=\n", derivative1) print("When x=1 f(x)'=", derivative1(1)) Output: Create Quiz Comment R rijushree100guha Follow 4 Improve R rijushree100guha Follow 4 Improve Article Tags : Python Python-numpy Python numpy-Mathematical Function Explore Python FundamentalsPython Introduction 2 min read Input and Output in Python 4 min read Python Variables 4 min read Python Operators 4 min read Python Keywords 2 min read Python Data Types 8 min read Conditional Statements in Python 3 min read Loops in Python - For, While and Nested Loops 5 min read Python Functions 5 min read Recursion in Python 4 min read Python Lambda Functions 5 min read Python Data StructuresPython String 5 min read Python Lists 4 min read Python Tuples 4 min read Python Dictionary 3 min read Python Sets 6 min read Python Arrays 7 min read List Comprehension in Python 4 min read Advanced PythonPython OOP Concepts 11 min read Python Exception Handling 5 min read File Handling in Python 4 min read Python Database Tutorial 4 min read Python MongoDB Tutorial 3 min read Python MySQL 9 min read Python Packages 10 min read Python Modules 3 min read Python DSA Libraries 15 min read List of Python GUI Library and Packages 3 min read Data Science with PythonNumPy Tutorial - Python Library 3 min read Pandas Tutorial 4 min read Matplotlib Tutorial 5 min read Python Seaborn Tutorial 3 min read StatsModel Library - Tutorial 3 min read Learning Model Building in Scikit-learn 6 min read TensorFlow Tutorial 2 min read PyTorch Tutorial 6 min read Web Development with PythonFlask Tutorial 8 min read Django Tutorial | Learn Django Framework 7 min read Django ORM - Inserting, Updating & Deleting Data 4 min read Templating With Jinja2 in Flask 6 min read Django Templates 5 min read Build a REST API using Flask - Python 3 min read Building a Simple API with Django REST Framework 3 min read Python PracticePython Quiz 1 min read Python Coding Practice 1 min read Python Interview Questions and Answers 15+ min read Like