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
Programming Articles
Page 214 of 2547
Add one Hermite series to another in Python
To add one Hermite series to another, use the polynomial.hermite.hermadd() method in Python NumPy. The method returns an array representing the Hermite series of their sum. Returns the sum of two Hermite series c1 + c2. The arguments are sequences of coefficients ordered from lowest order term to highest, i.e., [1, 2, 3] represents the series P_0 + 2*P_1 + 3*P_2. The parameters c1 and c2 are 1-D arrays of Hermite series coefficients ordered from low to high. Syntax numpy.polynomial.hermite.hermadd(c1, c2) Parameters c1, c2 − 1-D arrays of Hermite series coefficients ordered from ...
Read MoreReturn a boolean array which is True where the string element in array ends with suffix in Python
To return a boolean array which is True where the string element in array ends with a specific suffix, use the numpy.char.endswith() method. This function performs vectorized string operations on NumPy string arrays, checking each element for the specified suffix. Syntax numpy.char.endswith(a, suffix, start=0, end=None) Parameters a − Input array of strings suffix − String suffix to check for start − (Optional) Start position for checking end − (Optional) End position for checking Basic Example Let's create a string array and check which elements end with a specific suffix − ...
Read MoreGet the Inner product of two arrays in Python
The inner product of two arrays is computed using NumPy's inner() method. For 1-D arrays, it calculates the ordinary inner product of vectors. For higher dimensions, it performs a sum product over the last axes. Syntax numpy.inner(a, b) Parameters: a, b − Input arrays. If non-scalar, their last dimensions must match Basic Inner Product Example Let's calculate the inner product of two 1-D arrays ? import numpy as np # Create two 1-D arrays arr1 = np.array([5, 10, 15]) arr2 = np.array([20, 25, 30]) print("Array1:", arr1) print("Array2:", ...
Read MoreReturn the result of the power to which the negative input value is raised with scimath in Python
To return the result of the power to which the input value is raised with scimath, use the numpy.emath.power() method in Python. This function computes x to the power p (x**p) and automatically converts negative values to the complex domain when necessary. The numpy.emath.power() function handles negative bases gracefully by returning complex numbers, unlike the regular numpy.power() which may produce warnings or errors with negative values. Syntax numpy.emath.power(x, p) Parameters x − The base value(s). Can be a scalar or array containing negative values. p − The exponent(s). If x contains multiple values, ...
Read MoreReturn the result of the power to which the input value is raised with scimath in Python
The numpy.emath.power() function computes x raised to the power p (x**p) and handles negative values by converting results to the complex domain when necessary. This is particularly useful for mathematical operations that may produce complex results. Syntax numpy.emath.power(x, p) Parameters The function accepts the following parameters ? x − The base value(s). Can be a scalar or array-like. p − The exponent(s). Can be a scalar or array-like with the same shape as x. Basic Example with Positive Values Let's start with a simple example using positive integers ? ...
Read MoreCompute the natural logarithm with scimath in Python
To compute the natural logarithm with scimath, use the np.emath.log() method in Python NumPy. This function handles complex results automatically, making it safer than the standard np.log() for negative values. Syntax np.emath.log(x) Parameters: x − The value(s) whose natural logarithm is required. Can be scalar or array. Returns: The natural logarithm of x. For negative values, returns complex numbers with imaginary parts. Example with Mixed Values Let's compute the natural logarithm for various types of values including infinity and negative numbers − import numpy as np # ...
Read MoreCompute the square root of negative input with emath in Python
NumPy's emath.sqrt() function computes the square root of input values, handling negative numbers by returning complex values. Unlike the standard numpy.sqrt(), which raises an error for negative inputs, emath.sqrt() returns complex numbers for negative values. Syntax numpy.emath.sqrt(x) Parameters: x − Input array or scalar value Returns: Square root of x. For negative values, returns complex numbers with imaginary components. Example with Mixed Positive and Negative Values Let's compute square roots for an array containing both positive and negative numbers − import numpy as np # Creating a ...
Read MoreReturn the real part of the complex argument in Python
To return the real part of complex numbers in Python, use the numpy.real() method. This function extracts the real component from complex arguments. If the input contains real numbers, it returns them with their original type. For complex arrays, it returns float values. Syntax numpy.real(val) Parameters: val − Input array containing complex numbers Basic Example Let's extract real parts from a complex array ? import numpy as np # Create complex array arr = np.array([56.+0.j, 27.+0.j, 68.+0.j, 23.+0.j]) print("Original Array:", arr) # Extract real parts real_parts = ...
Read MoreCompute the square root of input with emath in Python
The numpy.emath.sqrt() function computes the square root of input values, returning complex numbers for negative inputs instead of raising errors. This function is part of NumPy's mathematical functions with automatic domain handling. Syntax numpy.emath.sqrt(x) Parameters: x − Input value (scalar or array-like). Can be positive, negative, or complex numbers. Returns: Square root of x. For negative inputs, returns complex numbers. Basic Example with Positive Numbers Let's compute square roots of positive numbers ? import numpy as np # Creating a numpy array with positive numbers arr = ...
Read MoreReturn real parts if input is complex with all imaginary parts close to zero in Python
The numpy.real_if_close() function returns the real parts of a complex array when the imaginary parts are close to zero. "Close to zero" is defined as tol * machine_epsilon, where tol is the tolerance parameter. Syntax numpy.real_if_close(a, tol=100) Parameters The function accepts the following parameters − a − Input array (complex or real) tol − Tolerance in machine epsilons (default: 100) Example Let's see how to extract real parts when imaginary parts are negligible − import numpy as np # Creating a complex array with very small ...
Read More