
- NumPy - Home
- NumPy - Introduction
- NumPy - Environment
- NumPy Arrays
- NumPy - Ndarray Object
- NumPy - Data Types
- NumPy Creating and Manipulating Arrays
- NumPy - Array Creation Routines
- NumPy - Array Manipulation
- NumPy - Array from Existing Data
- NumPy - Array From Numerical Ranges
- NumPy - Iterating Over Array
- NumPy - Reshaping Arrays
- NumPy - Concatenating Arrays
- NumPy - Stacking Arrays
- NumPy - Splitting Arrays
- NumPy - Flattening Arrays
- NumPy - Transposing Arrays
- NumPy Indexing & Slicing
- NumPy - Indexing & Slicing
- NumPy - Indexing
- NumPy - Slicing
- NumPy - Advanced Indexing
- NumPy - Fancy Indexing
- NumPy - Field Access
- NumPy - Slicing with Boolean Arrays
- NumPy Array Attributes & Operations
- NumPy - Array Attributes
- NumPy - Array Shape
- NumPy - Array Size
- NumPy - Array Strides
- NumPy - Array Itemsize
- NumPy - Broadcasting
- NumPy - Arithmetic Operations
- NumPy - Array Addition
- NumPy - Array Subtraction
- NumPy - Array Multiplication
- NumPy - Array Division
- NumPy Advanced Array Operations
- NumPy - Swapping Axes of Arrays
- NumPy - Byte Swapping
- NumPy - Copies & Views
- NumPy - Element-wise Array Comparisons
- NumPy - Filtering Arrays
- NumPy - Joining Arrays
- NumPy - Sort, Search & Counting Functions
- NumPy - Searching Arrays
- NumPy - Union of Arrays
- NumPy - Finding Unique Rows
- NumPy - Creating Datetime Arrays
- NumPy - Binary Operators
- NumPy - String Functions
- NumPy - Matrix Library
- NumPy - Linear Algebra
- NumPy - Matplotlib
- NumPy - Histogram Using Matplotlib
- NumPy Sorting and Advanced Manipulation
- NumPy - Sorting Arrays
- NumPy - Sorting along an axis
- NumPy - Sorting with Fancy Indexing
- NumPy - Structured Arrays
- NumPy - Creating Structured Arrays
- NumPy - Manipulating Structured Arrays
- NumPy - Record Arrays
- Numpy - Loading Arrays
- Numpy - Saving Arrays
- NumPy - Append Values to an Array
- NumPy - Swap Columns of Array
- NumPy - Insert Axes to an Array
- NumPy Handling Missing Data
- NumPy - Handling Missing Data
- NumPy - Identifying Missing Values
- NumPy - Removing Missing Data
- NumPy - Imputing Missing Data
- NumPy Performance Optimization
- NumPy - Performance Optimization with Arrays
- NumPy - Vectorization with Arrays
- NumPy - Memory Layout of Arrays
- Numpy Linear Algebra
- NumPy - Linear Algebra
- NumPy - Matrix Library
- NumPy - Matrix Addition
- NumPy - Matrix Subtraction
- NumPy - Matrix Multiplication
- NumPy - Element-wise Matrix Operations
- NumPy - Dot Product
- NumPy - Matrix Inversion
- NumPy - Determinant Calculation
- NumPy - Eigenvalues
- NumPy - Eigenvectors
- NumPy - Singular Value Decomposition
- NumPy - Solving Linear Equations
- NumPy - Matrix Norms
- NumPy Element-wise Matrix Operations
- NumPy - Sum
- NumPy - Mean
- NumPy - Median
- NumPy - Min
- NumPy - Max
- NumPy Set Operations
- NumPy - Unique Elements
- NumPy - Intersection
- NumPy - Union
- NumPy - Difference
- NumPy Random Number Generation
- NumPy - Random Generator
- NumPy - Permutations & Shuffling
- NumPy - Uniform distribution
- NumPy - Normal distribution
- NumPy - Binomial distribution
- NumPy - Poisson distribution
- NumPy - Exponential distribution
- NumPy - Rayleigh Distribution
- NumPy - Logistic Distribution
- NumPy - Pareto Distribution
- NumPy - Visualize Distributions With Sea born
- NumPy - Matplotlib
- NumPy - Multinomial Distribution
- NumPy - Chi Square Distribution
- NumPy - Zipf Distribution
- NumPy File Input & Output
- NumPy - I/O with NumPy
- NumPy - Reading Data from Files
- NumPy - Writing Data to Files
- NumPy - File Formats Supported
- NumPy Mathematical Functions
- NumPy - Mathematical Functions
- NumPy - Trigonometric functions
- NumPy - Exponential Functions
- NumPy - Logarithmic Functions
- NumPy - Hyperbolic functions
- NumPy - Rounding functions
- NumPy Fourier Transforms
- NumPy - Discrete Fourier Transform (DFT)
- NumPy - Fast Fourier Transform (FFT)
- NumPy - Inverse Fourier Transform
- NumPy - Fourier Series and Transforms
- NumPy - Signal Processing Applications
- NumPy - Convolution
- NumPy Polynomials
- NumPy - Polynomial Representation
- NumPy - Polynomial Operations
- NumPy - Finding Roots of Polynomials
- NumPy - Evaluating Polynomials
- NumPy Statistics
- NumPy - Statistical Functions
- NumPy - Descriptive Statistics
- NumPy Datetime
- NumPy - Basics of Date and Time
- NumPy - Representing Date & Time
- NumPy - Date & Time Arithmetic
- NumPy - Indexing with Datetime
- NumPy - Time Zone Handling
- NumPy - Time Series Analysis
- NumPy - Working with Time Deltas
- NumPy - Handling Leap Seconds
- NumPy - Vectorized Operations with Datetimes
- NumPy ufunc
- NumPy - ufunc Introduction
- NumPy - Creating Universal Functions (ufunc)
- NumPy - Arithmetic Universal Function (ufunc)
- NumPy - Rounding Decimal ufunc
- NumPy - Logarithmic Universal Function (ufunc)
- NumPy - Summation Universal Function (ufunc)
- NumPy - Product Universal Function (ufunc)
- NumPy - Difference Universal Function (ufunc)
- NumPy - Finding LCM with ufunc
- NumPy - ufunc Finding GCD
- NumPy - ufunc Trigonometric
- NumPy - Hyperbolic ufunc
- NumPy - Set Operations ufunc
- NumPy Useful Resources
- NumPy - Quick Guide
- NumPy - Cheatsheet
- NumPy - Useful Resources
- NumPy - Discussion
- NumPy Compiler
NumPy - Polynomial Operations
Polynomial Operations in NumPy
Polynomial operations in NumPy refer to various mathematical tasks you can perform on polynomials, such as addition, subtraction, multiplication, division, and evaluation.
NumPy makes it easy to work with polynomials by using arrays to represent their coefficients. You can use functions like numpy.polyadd(), numpy.polysub(), and numpy.polymul() to perform these operations, and methods like numpy.polyval() to evaluate a polynomial at specific values of x.
Adding Polynomials
Polynomials can be added using the numpy.polyadd() function in NumPy. The result is a new polynomial whose coefficients are the sum of the corresponding coefficients of the original polynomials.
Example: Polynomial Addition
In this example, we add two polynomials using the polyadd() function in NumPy −
import numpy as np # Define two polynomials using their coefficients # 1 + 2x + 3x p1 = np.array([1, 2, 3]) # 0 + 1x + 4x p2 = np.array([0, 1, 4]) # Add the polynomials using numpy.polyadd result_add = np.polyadd(p1, p2) print("Result of polynomial addition:", result_add)
The result of adding the two polynomials is −
Result of polynomial addition: [1 3 7]
Subtracting Polynomials
Polynomials can be subtracted using the numpy.polysub() function. The result is a new polynomial whose coefficients are the differences of the corresponding coefficients of the original polynomials.
Example: Polynomial Subtraction
In this example, we subtract one polynomial from another using the polysub() function in NumPy −
import numpy as np # Define two polynomials using their coefficients # 1 + 2x + 3x p1 = np.array([1, 2, 3]) # 0 + 1x + 4x p2 = np.array([0, 1, 4]) # Subtract the polynomials using numpy.polysub result_sub = np.polysub(p1, p2) print("Result of polynomial subtraction:", result_sub)
The result of subtracting the two polynomials is −
Result of polynomial subtraction: [ 1 1 -1]
Multiplying Polynomials
Polynomials can be multiplied using the numpy.polymul() function. The multiplication of two polynomials is carried out by multiplying each term in the first polynomial by each term in the second polynomial and summing the results.
Example: Polynomial Multiplication
In this example, we multiply two polynomials using the polymul() function in NumPy −
import numpy as np # Define two polynomials using their coefficients # 1 + 2x + 3x p1 = np.array([1, 2, 3]) # 0 + 1x + 4x p2 = np.array([0, 1, 4]) # Multiply the polynomials using numpy.polymul result_mul = np.polymul(p1, p2) print("Result of polynomial multiplication:", result_mul)
The result of multiplying the two polynomials is −
Result of polynomial multiplication: [ 1 6 11 12]
Evaluating Polynomials
The numpy.polyval() function is used to evaluate a polynomial at a specific value of x. This can be useful for finding the value of the polynomial for any given x.
Example: Polynomial Evaluation
In this example, we evaluate the polynomial at x = 2 using the polyval() function −
import numpy as np # Define polynomial using its coefficients # 1 + 2x + 3x p1 = np.array([1, 2, 3]) # Evaluate the polynomial at x = 2 using numpy.polyval x_value = 2 result_eval = np.polyval(p1, x_value) print(f"Polynomial evaluated at x = {x_value}:", result_eval)
The result of evaluating the polynomial at x = 2 is −
Polynomial evaluated at x = 2: 11
Polynomial Differentiation
Polynomials can be differentiated using the numpy.polyder() function. The derivative of a polynomial is a new polynomial obtained by differentiating each term of the original polynomial with respect to the variable.
Example: Polynomial Differentiation
In this example, we differentiate the polynomial using the polyder() function in NumPy −
import numpy as np # Define polynomial using its coefficients # 1 + 2x + 3x p1 = np.array([1, 2, 3]) # Differentiate the polynomial using numpy.polyder derivative = np.polyder(p1) print("Derivative of the polynomial:", derivative)
The result of differentiating the polynomial is −
Derivative of the polynomial: [2 2]
Polynomial Integration
Polynomials can be integrated using the numpy.polyint() function. The integral of a polynomial is a new polynomial obtained by integrating each term of the original polynomial with respect to the variable.
Example: Polynomial Integration
In this example, we integrate the polynomial using the polyint() function in NumPy −
import numpy as np # Define polynomial using its coefficients # 1 + 2x + 3x p1 = np.array([1, 2, 3]) # Integrate the polynomial using numpy.polyint integral = np.polyint(p1) print("Integral of the polynomial:", integral)
The result of integrating the polynomial is −
Integral of the polynomial: [0.33333333 1. 3. 0. ]