Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
Selected Reading
Integrate a Hermite series over specific axis in Python
To integrate a Hermite series, use the hermite.hermint() method in Python. This method integrates Hermite series coefficients over a specified axis, making it useful for polynomial integration in scientific computing.
Syntax
numpy.polynomial.hermite.hermint(c, m=1, k=[], lbnd=0, scl=1, axis=0)
Parameters
| Parameter | Description | Default |
|---|---|---|
| c | Array of Hermite series coefficients | Required |
| m | Order of integration (must be positive) | 1 |
| k | Integration constant(s) | [] (zero) |
| lbnd | Lower bound of the integral | 0 |
| scl | Scalar multiplier after each integration | 1 |
| axis | Axis over which integration is performed | 0 |
Example
Let's create a multidimensional array and integrate along different axes ?
import numpy as np
from numpy.polynomial import hermite as H
# Create a multidimensional array of coefficients
c = np.arange(4).reshape(2,2)
# Display the array
print("Our Array...\n",c)
# Check the Dimensions
print("\nDimensions of our Array...\n",c.ndim)
# Get the Datatype
print("\nDatatype of our Array object...\n",c.dtype)
# Get the Shape
print("\nShape of our Array object...\n",c.shape)
# To integrate a Hermite series, use the hermite.hermint() method in Python
print("\nResult (axis=1)...\n",H.hermint(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 (axis=1)... [[0.5 0. 0.25] [1.5 1. 0.75]]
Integration Along Different Axes
Compare integration along axis 0 vs axis 1 ?
import numpy as np
from numpy.polynomial import hermite as H
c = np.arange(6).reshape(2,3)
print("Original array:")
print(c)
print("\nIntegration along axis=0:")
print(H.hermint(c, axis=0))
print("\nIntegration along axis=1:")
print(H.hermint(c, axis=1))
Original array: [[0 1 2] [3 4 5]] Integration along axis=0: [[1.5 0. 2.5 1. 3.5]] Integration along axis=1: [[0.5 0. 0.25 0. 0.5 ] [2.5 1.5 1. 0.75 1.25]]
Using Integration Constants
Add integration constants using the k parameter ?
import numpy as np
from numpy.polynomial import hermite as H
c = np.array([1, 2, 3])
print("Coefficients:", c)
# Integration with constant k=5
result_with_k = H.hermint(c, k=5)
print("With integration constant k=5:")
print(result_with_k)
# Integration without constant (default k=[])
result_default = H.hermint(c)
print("Without integration constant:")
print(result_default)
Coefficients: [1 2 3] With integration constant k=5: [5. 0.5 1. 0.75] Without integration constant: [0. 0.5 1. 0.75]
Conclusion
The hermite.hermint() method provides flexible integration of Hermite series with control over axes, integration order, and constants. Use the axis parameter to specify which dimension to integrate along in multidimensional arrays.
Advertisements
