Programming Articles

Page 217 of 2547

Raise a polynomial to a power in Python

AmitDiwan
AmitDiwan
Updated on 26-Mar-2026 809 Views

To raise a polynomial to a power in Python, use the numpy.polynomial.polynomial.polypow() method. This function returns the polynomial raised to the specified power, where coefficients are ordered from low to high degree. Syntax numpy.polynomial.polynomial.polypow(c, pow, maxpower=16) Parameters The function accepts the following parameters: c − A 1-D array of polynomial coefficients ordered from low to high degree (e.g., [1, 2, 3] represents 1 + 2*x + 3*x²) pow − The power to which the polynomial will be raised maxpower − Maximum power allowed to limit series growth (default is 16) ...

Read More

Divide one polynomial by another in Python

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

To divide one polynomial by another in Python, use the numpy.polynomial.polynomial.polydiv() method. This function performs polynomial division and returns both the quotient and remainder. The arguments are sequences of coefficients from lowest order term to highest, e.g., [1, 2, 3] represents 1 + 2*x + 3*x². Syntax numpy.polynomial.polynomial.polydiv(c1, c2) Parameters The parameters are ? c1 − 1-D array of coefficients for the dividend polynomial c2 − 1-D array of coefficients for the divisor polynomial Return Value Returns a tuple containing two arrays ? Quotient − Array of ...

Read More

Array axis summations with Einstein summation convention in Python

AmitDiwan
AmitDiwan
Updated on 26-Mar-2026 281 Views

The einsum() method evaluates the Einstein summation convention on operands. Using the Einstein summation convention, many common multi-dimensional, linear algebraic array operations can be represented in a simple fashion. This method provides flexibility to compute array operations including axis summations by specifying subscript labels. For array axis summations with Einstein summation convention, use the numpy.einsum() method. The first parameter is the subscript string that specifies the summation pattern, and the second parameter is the input array. Syntax numpy.einsum(subscripts, *operands) Parameters subscripts − String specifying the subscripts for summation as comma separated list ...

Read More

Extract the diagonal of a matrix with Einstein summation convention in Python

AmitDiwan
AmitDiwan
Updated on 26-Mar-2026 976 Views

The Einstein summation convention provides a concise way to express array operations. The numpy.einsum() method implements this convention, allowing us to extract matrix diagonals using subscript notation like 'ii->i'. Understanding Einstein Summation for Diagonals The subscript 'ii->i' means we take elements where both indices are equal (diagonal elements) and output them as a 1D array. The repeated index i on the left indicates we want elements at positions (0, 0), (1, 1), (2, 2), etc. Basic Example Here's how to extract diagonal elements from a 4x4 matrix ? import numpy as np # ...

Read More

Get the trace of a matrix with Einstein summation convention in Python

AmitDiwan
AmitDiwan
Updated on 26-Mar-2026 735 Views

The einsum() method evaluates the Einstein summation convention on operands. Using the Einstein summation convention, many common multi-dimensional, linear algebraic array operations can be represented in a simple fashion. To get the trace of a matrix with Einstein summation convention, use the numpy.einsum() method. The trace is the sum of diagonal elements, which can be computed using the subscript 'ii'. Syntax numpy.einsum(subscripts, *operands) Parameters: subscripts − String specifying the subscripts for summation operands − Input arrays for the operation Basic Example Let's create a 4x4 matrix and calculate its trace ...

Read More

Return the angle of the complex argument in Python

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

To return the angle of the complex argument, use the numpy.angle() method in Python. The method returns the counterclockwise angle from the positive real axis on the complex plane in the range (-pi, pi], with dtype as numpy.float64. Syntax numpy.angle(z, deg=False) Parameters z − A complex number or sequence of complex numbers deg − Return angle in degrees if True, radians if False (default) Basic Example Let's create an array of complex numbers and find their angles − import numpy as np # Create an array of ...

Read More

Return the bases when first array elements are raised to powers from second array in Python

AmitDiwan
AmitDiwan
Updated on 26-Mar-2026 246 Views

To return the bases when first array elements are raised to powers from second array, use the np.float_power() method in Python NumPy. This function raises each base in the first array to the positionally-corresponding power in the second array, returning floating-point results with a minimum precision of float64. The float_power() method differs from the standard power() function by promoting integers, float16, and float32 to floats with higher precision, ensuring the result is always inexact. This provides more usable results for negative powers and reduces overflow for positive powers. Syntax numpy.float_power(x1, x2) Parameters x1: ...

Read More

Return a boolean array which is True where the string element in array starts with prefix in Python

AmitDiwan
AmitDiwan
Updated on 26-Mar-2026 389 Views

To return a boolean array which is True where string elements start with a specific prefix, use the numpy.char.startswith() method in NumPy. This function takes the input array as the first parameter and the prefix string as the second parameter. Syntax numpy.char.startswith(a, prefix, start=0, end=None) Parameters a − Input array of strings prefix − String prefix to check for start − Optional start position (default: 0) end − Optional end position (default: None) Basic Example Let's create a string array and check which elements start with the prefix 'K' − ...

Read More

Return the multiple vector cross product of two vectors and change the orientation of the result in Python

AmitDiwan
AmitDiwan
Updated on 26-Mar-2026 244 Views

To compute the cross product of two vectors and change the orientation of the result, use the numpy.cross() method in Python NumPy. The method returns the vector cross product(s) with customizable axis orientation. Parameters The numpy.cross() method accepts several parameters to control vector orientation: a: Components of the first vector(s) b: Components of the second vector(s) axisa: Axis of a that defines the vector(s) (default: last axis) axisb: Axis of b that defines the vector(s) (default: last axis) axisc: Axis of c containing the cross product vector(s) (default: last axis) axis: Overrides axisa, axisb and axisc ...

Read More

Generate a Pseudo Vandermonde matrix of Hermite polynomial and x, y, z floating array of points in Python

AmitDiwan
AmitDiwan
Updated on 26-Mar-2026 172 Views

To generate a pseudo Vandermonde matrix of the Hermite polynomial and x, y, z sample points, use the hermite.hermvander3d() method in NumPy. This method returns the pseudo-Vandermonde matrix where the parameter x, y, z are arrays of point coordinates, all of the same shape. The deg parameter is a list of maximum degrees of the form [x_deg, y_deg, z_deg]. Syntax The basic syntax is ? hermite.hermvander3d(x, y, z, deg) Parameters x, y, z ? Arrays of point coordinates, all of the same shape deg ? List of maximum degrees in the form ...

Read More
Showing 2161–2170 of 25,469 articles
« Prev 1 215 216 217 218 219 2547 Next »
Advertisements