Differentiate a Legendre series with multidimensional coefficients over specific axis in Python

To differentiate a Legendre series with multidimensional coefficients, use the numpy.polynomial.legendre.legder() method. This function returns the Legendre series coefficients differentiated m times along a specified axis.

Syntax

numpy.polynomial.legendre.legder(c, m=1, scl=1, axis=0)

Parameters

The function accepts the following parameters ?

  • c ? Array of Legendre series coefficients. For multidimensional arrays, different axes correspond to different variables
  • m ? Number of derivatives taken (default: 1). Must be non-negative
  • scl ? Scalar multiplier for each differentiation (default: 1). Final result is multiplied by scl**m
  • axis ? Axis over which the derivative is taken (default: 0)

Example

Let's differentiate a Legendre series with multidimensional coefficients over axis 1 ?

import numpy as np
from numpy.polynomial import legendre as L

# Create a multidimensional array of coefficients
c = np.arange(4).reshape(2,2)

# Display the array
print("Our Array...")
print(c)

# Check the Dimensions
print("\nDimensions of our Array...")
print(c.ndim)

# Get the Datatype
print("\nDatatype of our Array object...")
print(c.dtype)

# Get the Shape
print("\nShape of our Array object...")
print(c.shape)

# Differentiate along axis 1
print("\nResult (differentiated along axis 1)...")
print(L.legder(c, axis=1))
Our Array...
[[0 1]
 [2 3]]

Dimensions of our Array...
2

Datatype of our Array object...
int64

Shape of our Array object...
(2, 2)

Result (differentiated along axis 1)...
[[1.]
 [3.]]

Multiple Derivatives

You can also take multiple derivatives by specifying the m parameter ?

import numpy as np
from numpy.polynomial import legendre as L

# Create coefficients for higher-degree polynomial
c = np.array([[0, 1, 2], [3, 4, 5]])
print("Original coefficients:")
print(c)

# Take second derivative along axis 1
print("\nSecond derivative along axis 1:")
print(L.legder(c, m=2, axis=1))
Original coefficients:
[[0 1 2]
 [3 4 5]]

Second derivative along axis 1:
[[6.]
 [6.]]

How It Works

The Legendre polynomial differentiation follows the mathematical relationship where the derivative of a Legendre series reduces the degree by one. When working with multidimensional coefficients, the function operates along the specified axis, treating other dimensions as separate polynomial series.

Conclusion

Use numpy.polynomial.legendre.legder() to differentiate Legendre series with multidimensional coefficients. The axis parameter controls which dimension to differentiate along, while m specifies the order of differentiation.

Updated on: 2026-03-26T21:12:28+05:30

212 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements