# Differentiate a Legendre series and set the derivatives using NumPy in Python

• Last Updated : 03 Jun, 2022

In this article, we will cover how to differentiate a Legendre series and set the derivatives using NumPy in Python.

## numpy.polynomial.legendre.legder

The numpy.polynomial.legendre.legder() method from the NumPy library is used to differentiate a Legendre series and set the derivatives in Python. The Legendre series coefficients c differed m times along the axis are returned. The result is multiplied by scl at each iteration . The c argument is an array of coefficients ranging in degree from low to high along each axis, such as [4,3,2]. indicates the series 4 *L 0 + 3*L 1 + 2*L 2, whereas [[2,1],[2,1]] indicates 2 *L 0(x)*L 0(y) + 2*L 1(x)*L 0(y) + 1*L 0(x)*L 1(y) + 1*L 1(x)*L 1(y) .If axis=0 is x and axis=1 is y.

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

Parameters:

• c: array like object.
• m: int , optional. The total number of derivatives taken must not be negative. It is set to 1 by default.
• axis: optional value, int. The axis on which the derivative is computed. It is set to 0 by default.

Returns: Legendre series of the derivative.

### Example 1:

Here, we will create a NumPy array and use polynomial.legendre.legder()  to differentiate a Legendre series where the series is an array of coefficients. The shape of the array is found by the .shape attribute, the dimension of the array is found by .ndim attribute, and the data type of the array is .dtype attribute.

## Python3

 `# import packages``import` `numpy as np``from` `numpy.polynomial ``import` `legendre as L`` ` `# array of coefficients``array ``=` `np.array([``10``,``20``,``30``,``40``])``print``(array)`` ` `# shape of the array is``print``(``"Shape of the array is : "``,array.shape)`` ` `# dimension of the array``print``(``"The dimension of the array is : "``,array.ndim)`` ` `# differenciate Legendre series``print``(L.legder(array,``2``))`

Output:

```[10 20 30 40]
Shape of the array is :  (4,)
The dimension of the array is :  1
[ 90. 600.]```

### Example 2:

In this example, a 2d array of Coefficients is given as input and the axis parameter is given a value of ‘1’ which specifies that the derivative is computed on the columns.

## Python3

 `# import packages``import` `numpy as np``from` `numpy.polynomial ``import` `legendre as L`` ` `# array of coefficients``array ``=` `np.array([[``10``,``20``],[``30``,``40``]])``print``(array)`` ` `# shape of the array is``print``(``"Shape of the array is : "``,array.shape)`` ` `# dimension of the array``print``(``"The dimension of the array is : "``,array.ndim)`` ` `# differenciate Legendre series``print``(L.legder(array,``1``,axis ``=``1``))`

Output:

```[[10 20]
[30 40]]
Shape of the array is :  (2, 2)
The dimension of the array is :  2
[[20.]
[40.]]```

My Personal Notes arrow_drop_up