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 211 of 2547
Compute 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 MoreReplace NaN with zero and fill positive infinity for complex input values in Python
The numpy.nan_to_num() function replaces NaN values with zero and infinity values with large finite numbers. This is particularly useful when working with complex numbers that contain non-finite values. Syntax numpy.nan_to_num(x, copy=True, nan=0.0, posinf=None, neginf=None) Parameters The function accepts the following parameters − x − Input data (array-like) copy − Whether to create a copy (True) or replace in-place (False). Default is True nan − Value to replace NaN. Default is 0.0 posinf − Value to replace positive infinity. Default is very large finite number neginf − Value to replace negative infinity. Default ...
Read MoreReplace NaN with zero and fill negative infinity values in Python
In NumPy, you can handle NaN and infinity values using the numpy.nan_to_num() method. This function replaces NaN with zero and infinity values with large finite numbers, making your data suitable for mathematical operations. Syntax numpy.nan_to_num(x, copy=True, nan=0.0, posinf=None, neginf=None) Parameters Parameter Description Default x Input array Required copy Whether to create a copy or modify in-place True nan Value to replace NaN with 0.0 posinf Value to replace positive infinity with Very large number neginf Value to replace negative infinity with Very ...
Read MoreReturn the discrete linear convolution of two one-dimensional sequences in Python
To return the discrete linear convolution of two one-dimensional sequences, use the numpy.convolve() method in Python NumPy. The convolution operator is often seen in signal processing, where it models the effect of a linear time-invariant system on a signal. In probability theory, the sum of two independent random variables is distributed according to the convolution of their individual distributions. Syntax numpy.convolve(a, v, mode='full') Parameters The method accepts the following parameters ? a ? First one-dimensional input array v ? Second one-dimensional input array mode ? Optional parameter with values 'full', 'valid', ...
Read MoreConvert a polynomial to a Chebyshev series in Python
To convert a polynomial to a Chebyshev series, use the chebyshev.poly2cheb() method in Python NumPy. This method converts an array representing polynomial coefficients (ordered from lowest degree to highest) to an array of coefficients for the equivalent Chebyshev series. Syntax numpy.polynomial.chebyshev.poly2cheb(pol) Parameters pol − A 1-D array containing polynomial coefficients ordered from lowest to highest degree. Return Value Returns a 1-D array containing the coefficients of the equivalent Chebyshev series, ordered from lowest to highest degree. Example Let's convert a polynomial with coefficients [1, 2, 3, 4, 5] to its ...
Read MoreConvert a Chebyshev series to a polynomial in Python
To convert a Chebyshev series to a polynomial, use the chebyshev.cheb2poly() method in Python NumPy. This function converts an array representing the coefficients of a Chebyshev series, ordered from lowest degree to highest, to an array of the coefficients of the equivalent polynomial (relative to the "standard" basis) ordered from lowest to highest degree. The method returns a 1-D array containing the coefficients of the equivalent polynomial ordered from lowest order term to highest. The parameter c is a 1-D array containing the Chebyshev series coefficients, ordered from lowest order term to highest. Syntax numpy.polynomial.chebyshev.cheb2poly(c) ...
Read MoreRemove small trailing coefficients from Chebyshev polynomial in Python
To remove small trailing coefficients from Chebyshev polynomial, use the chebyshev.chebtrim() method in Python NumPy. This method returns a 1-d array with trailing zeros removed. If the resulting series would be empty, a series containing a single zero is returned. The "Small" means "small in absolute value" and is controlled by the parameter tol. "Trailing" means highest order coefficient(s). For example, in [0, 1, 1, 0, 0] (which represents 0 + x + x² + 0×x³ + 0×x⁴), both the 3rd and 4th order coefficients would be "trimmed." Syntax numpy.polynomial.chebyshev.chebtrim(c, tol=0) Parameters ...
Read MoreEvaluate a Hermite series at points x when coefficients are multi-dimensional in Python
To evaluate a Hermite series at points x with multi-dimensional coefficients, use the hermite.hermval() method in NumPy. This function allows you to evaluate multiple Hermite polynomials simultaneously when coefficients are stored in a multi-dimensional array. Syntax numpy.polynomial.hermite.hermval(x, c, tensor=True) Parameters The function accepts three parameters: x: Points at which to evaluate the series. Can be a scalar, list, or array. c: Array of coefficients where coefficients for degree n are in c[n]. For multi-dimensional arrays, additional indices represent multiple polynomials. tensor: Boolean (default True). Controls how x and c are combined during ...
Read MoreEvaluate a Hermite series at points x in Python
To evaluate a Hermite series at points x, use the hermite.hermval() method in Python NumPy. This function evaluates a Hermite polynomial series at given points using the coefficients provided. Syntax numpy.polynomial.hermite.hermval(x, c, tensor=True) Parameters The function accepts three parameters ? x: Points at which to evaluate the Hermite series. Can be a scalar, list, or array. c: Array of coefficients ordered so that coefficients for terms of degree n are in c[n]. tensor: If True (default), evaluates each coefficient column for every element of x. If False, broadcasts x over coefficient columns. ...
Read More