Numpy Articles

Page 38 of 81

Evaluate a polynomial specified by its roots at points x in Python

AmitDiwan
AmitDiwan
Updated on 26-Mar-2026 249 Views

To evaluate a polynomial specified by its roots at points x, use the polynomial.polyvalfromroots() method in Python NumPy. This function calculates the polynomial value at given points when you know the polynomial's roots rather than its coefficients. Syntax numpy.polynomial.polynomial.polyvalfromroots(x, r, tensor=True) Parameters x: Array of points where to evaluate the polynomial. If x is a list or tuple, it is converted to an ndarray, otherwise it is left unchanged and treated as a scalar. r: Array of roots. If r is multidimensional, the first index is the root index, while the remaining indices ...

Read More

Generate a pseudo Vandermonde matrix of the Chebyshev polynomial in Python

AmitDiwan
AmitDiwan
Updated on 26-Mar-2026 209 Views

To generate a pseudo Vandermonde matrix of the Chebyshev polynomial, use the chebyshev.chebvander2d() function in NumPy. This method returns the pseudo-Vandermonde matrix of degrees deg and sample points (x, y). The parameters x and y are arrays of point coordinates, all of the same shape. The dtypes will be converted to either float64 or complex128 depending on whether any of the elements are complex. Scalars are converted to 1-D arrays. The parameter deg is a list of maximum degrees of the form [x_deg, y_deg]. Syntax numpy.polynomial.chebyshev.chebvander2d(x, y, deg) Parameters x, y − ...

Read More

Generate a Vandermonde matrix of the Chebyshev polynomial with complex array of points in Python

AmitDiwan
AmitDiwan
Updated on 26-Mar-2026 209 Views

To generate a Vandermonde matrix of the Chebyshev polynomial with complex points, use the chebyshev.chebvander() function in Python NumPy. This function returns a Vandermonde matrix where each column represents a Chebyshev polynomial of increasing degree evaluated at the given points. Syntax numpy.polynomial.chebyshev.chebvander(x, deg) Parameters The function accepts the following parameters: x: Array of points (can be complex). The dtype is converted to float64 or complex128 depending on whether any elements are complex deg: Degree of the resulting matrix. The returned matrix will have deg + 1 columns Return Value ...

Read More

Generate a Vandermonde matrix of the Chebyshev polynomial with float array of points in Python

AmitDiwan
AmitDiwan
Updated on 26-Mar-2026 190 Views

To generate a Vandermonde matrix of the Chebyshev polynomial, use numpy.polynomial.chebyshev.chebvander(). This function returns a Vandermonde matrix where each column represents a different degree of the Chebyshev polynomial evaluated at the input points. Syntax numpy.polynomial.chebyshev.chebvander(x, deg) Parameters The function accepts the following parameters: x: Array of points. The dtype is converted to float64 or complex128 depending on whether any elements are complex. If x is scalar, it is converted to a 1-D array. deg: Degree of the resulting matrix. This determines the number of Chebyshev polynomial terms to include. Return ...

Read More

Return the cumulative sum of array elements treating NaNs as zero but change the type of result in Python

AmitDiwan
AmitDiwan
Updated on 26-Mar-2026 208 Views

To return the cumulative sum of array elements over a given axis treating NaNs as zero, use the numpy.nancumsum() method. The cumulative sum does not change when NaNs are encountered and leading NaNs are replaced by zeros. Zeros are returned for slices that are all-NaN or empty. Syntax numpy.nancumsum(a, axis=None, dtype=None, out=None) Parameters The function accepts the following parameters: a − Input array axis − Axis along which the cumulative sum is computed. Default is None (flattened array) dtype − ...

Read More

Return True if cast between data types can occur according to the casting rule in Python

AmitDiwan
AmitDiwan
Updated on 26-Mar-2026 196 Views

The numpy.can_cast() method returns True if a cast between data types can occur according to NumPy's casting rules. It takes two parameters: the source data type and the target data type to cast to. Syntax numpy.can_cast(from_dtype, to_dtype, casting='safe') Parameters from_dtype: The data type or array to cast from to_dtype: The data type to cast to casting: Controls what kind of data casting may occur ('no', 'equiv', 'safe', 'same_kind', 'unsafe') Basic Usage Let's check if various data type conversions are possible ? import numpy as np print("Checking with can_cast() method ...

Read More

Convert an array of datetimes into an array of strings passing units in Python

AmitDiwan
AmitDiwan
Updated on 26-Mar-2026 405 Views

To convert an array of datetimes into an array of strings, use the numpy.datetime_as_string() method in Python NumPy. The method returns an array of strings the same shape as the input array. The first parameter is the array of UTC timestamps to format. The "units" parameter sets the datetime unit to change the precision. Syntax numpy.datetime_as_string(arr, unit=None, timezone='naive', casting='same_kind') Parameters The key parameters are ? arr − Array of datetime64 values to convert unit − Datetime unit for precision ('Y', 'M', 'D', 'h', 'm', 's', 'ms', etc.) timezone − Timezone handling ('naive', ...

Read More

Return an array with the number of nonoverlapping occurrences of substring in Python

AmitDiwan
AmitDiwan
Updated on 26-Mar-2026 260 Views

To return an array with the number of non-overlapping occurrences of substring, use the numpy.char.count() method in Python NumPy. The numpy.char module provides vectorized string operations for arrays of type numpy.str_ or numpy.bytes_. Syntax numpy.char.count(a, sub, start=0, end=None) Parameters a − Input array of strings sub − Substring to search for start − Optional start position (default: 0) end − Optional end position (default: None) Example 1: Basic Character Count Count occurrences of a specific character in string array ? import numpy as np # Create a One-Dimensional array ...

Read More

Round to nearest integer towards zero in Python

AmitDiwan
AmitDiwan
Updated on 26-Mar-2026 2K+ Views

To round to the nearest integer towards zero in Python, use the numpy.fix() method. It performs element-wise rounding of float arrays towards zero, which means it truncates the decimal part. For positive numbers, this rounds down, and for negative numbers, it rounds up towards zero. Syntax numpy.fix(x, out=None) Parameters The function accepts the following parameters: x − Array of floats to be rounded out − Optional output array where results are stored Basic Example Let's see how np.fix() rounds different types of numbers ? import numpy as ...

Read More

Multiply one polynomial to another in Python

AmitDiwan
AmitDiwan
Updated on 26-Mar-2026 2K+ Views

To multiply one polynomial to another, use the numpy.polynomial.polynomial.polymul() method in Python. This function returns the multiplication of two polynomials represented as coefficient arrays. The arguments are sequences of coefficients from lowest order term to highest, i.e., [1, 2, 3] represents the polynomial 1 + 2*x + 3*x². The method returns the coefficient array representing their product. The parameters c1 and c2 are 1-D arrays of coefficients representing polynomials, ordered from lowest order term to highest. Syntax numpy.polynomial.polynomial.polymul(c1, c2) Parameters: c1 − 1-D array of polynomial coefficients (lowest to highest order) c2 − ...

Read More
Showing 371–380 of 802 articles
« Prev 1 36 37 38 39 40 81 Next »
Advertisements