Articles on Trending Technologies

Technical articles with clear explanations and examples

Get the Machine limits information for float types in Python

AmitDiwan
AmitDiwan
Updated on 26-Mar-2026 946 Views

To get the machine limits information for float types, use the numpy.finfo() method in Python NumPy. The first parameter is the floating type i.e. the kind of float data type to get information about. Syntax numpy.finfo(dtype) Where dtype is the floating-point data type such as float16, float32, or float64. Getting Float16 Limits Check the machine limits for 16-bit floating-point numbers ? import numpy as np # Get machine limits for float16 a = np.finfo(np.float16) print("Minimum of float16 type...") print(a.min) print("Maximum of float16 type...") print(a.max) Minimum of float16 ...

Read More

Get the Machine limits information for integer types in Python

AmitDiwan
AmitDiwan
Updated on 26-Mar-2026 419 Views

To get machine limits information for integer types in Python, use the numpy.iinfo() method. This function returns an object containing the minimum and maximum values for a specified integer data type, helping you understand the range of values that can be stored. Syntax numpy.iinfo(int_type) Parameters: int_type − The integer data type to get information about (e.g., np.int16, np.int32, np.int64) Basic Example Let's check the limits for different integer types ? import numpy as np # Get machine limits for int16 info_16 = np.iinfo(np.int16) print("int16 minimum:", info_16.min) print("int16 maximum:", ...

Read More

Return a scalar type which is common to the input arrays in Python

AmitDiwan
AmitDiwan
Updated on 26-Mar-2026 579 Views

To return a scalar type which is common to the input arrays, use the numpy.common_type() method in Python NumPy. This method finds the most appropriate data type that can represent all input arrays without losing precision. The return type will always be an inexact (i.e. floating point) scalar type, even if all the arrays are integer arrays. All input arrays except int64 and uint64 can be safely cast to the returned dtype without loss of information. If one of the inputs is an integer array, the minimum precision type returned is a 64-bit floating point dtype. Syntax ...

Read More

Return the base 2 logarithm for complex value input in Python

AmitDiwan
AmitDiwan
Updated on 26-Mar-2026 419 Views

The numpy.log2() function computes the base-2 logarithm of array elements. When working with complex numbers, it returns complex logarithmic values using the formula log₂(z) = ln(z) / ln(2). Syntax numpy.log2(x, out=None, where=True) Parameters The function accepts the following parameters − x − Input array or scalar value out − Optional output array to store results where − Condition to broadcast over input Example with Complex Numbers Here's how to calculate base-2 logarithm for complex values − import numpy as np # Create an array with complex ...

Read More

Determine common type following standard coercion rules in Python

AmitDiwan
AmitDiwan
Updated on 26-Mar-2026 264 Views

In NumPy, find_common_type() determines the common data type following standard coercion rules. This function helps when working with mixed data types in arrays and scalars, returning the most appropriate common type. Syntax numpy.find_common_type(array_types, scalar_types) Parameters The function takes two parameters: array_types − A list of dtypes or dtype convertible objects representing arrays scalar_types − A list of dtypes or dtype convertible objects representing scalars How It Works The method returns the common data type, which is the maximum of array_types ignoring scalar_types, unless the maximum of scalar_types is of ...

Read More

Return the length of a string array element-wise in Python

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

To return the length of a string array element-wise, use the numpy.char.str_len() method in Python NumPy. The method returns an output array of integers representing the length of each string element. Syntax numpy.char.str_len(a) Parameters: a − Array-like of str or unicode Returns: Array of integers representing the length of each string element. Basic Example Let's create a simple string array and find the length of each element ? import numpy as np # Create array of strings names = np.array(['Amy', 'Scarlett', 'Katie', 'Brad', 'Tom']) # Get ...

Read More

Test whether similar int type of different sizes are subdtypes of integer class in Python

AmitDiwan
AmitDiwan
Updated on 26-Mar-2026 182 Views

To test whether similar int type of different sizes are subdtypes of integer class, use the numpy.issubdtype() method in Python NumPy. The parameters are the dtype or object coercible to one. Syntax numpy.issubdtype(arg1, arg2) Parameters: arg1: dtype or object coercible to one arg2: dtype or object coercible to one Returns: Boolean value indicating whether arg1 is a subtype of arg2. Testing Signed Integer Subtypes First, let's check if different sized integer types are subtypes of np.signedinteger − import numpy as np # Testing different signed integer sizes ...

Read More

How to change the attributes of a networkx / matplotlib graph drawing?

Rishikesh Kumar Rishi
Rishikesh Kumar Rishi
Updated on 26-Mar-2026 2K+ Views

To change the attributes of a NetworkX/matplotlib graph drawing, you can customize various visual properties like edge colors, weights, node colors, and layouts. This allows you to create more informative and visually appealing network visualizations. Steps Set the figure size and adjust the padding between and around the subplots. Initialize a graph with edges, name, or graph attributes. Add edges with custom attributes like color and weight. Extract edge attributes using NetworkX methods. Position the nodes using a layout algorithm. Draw the graph with customized visual attributes. Display the figure using the show() method. Example ...

Read More

How to fill an area within a polygon in Python using matplotlib?

Rishikesh Kumar Rishi
Rishikesh Kumar Rishi
Updated on 26-Mar-2026 2K+ Views

Matplotlib provides several ways to fill areas within polygons. The most common approaches are using Polygon patches, fill() method, or PatchCollection for multiple polygons. Method 1: Using fill() Method The simplest way to fill a polygon is using matplotlib's fill() method ? import matplotlib.pyplot as plt import numpy as np # Define polygon vertices (triangle) x = [1, 4, 2] y = [1, 2, 4] plt.figure(figsize=(8, 6)) plt.fill(x, y, color='lightblue', alpha=0.7, edgecolor='blue') plt.title('Filled Triangle Polygon') plt.grid(True, alpha=0.3) plt.show() Method 2: Using Polygon Patch For more control over polygon properties, use Polygon ...

Read More

How to get data labels on a Seaborn pointplot?

Rishikesh Kumar Rishi
Rishikesh Kumar Rishi
Updated on 26-Mar-2026 3K+ Views

To get data labels on a Seaborn pointplot, you need to access the plotted points and add annotations manually using matplotlib's annotate() function. This technique helps display exact values on each data point for better visualization. Steps Set the figure size and adjust the padding between and around the subplots. Create a DataFrame with sample data for visualization. Create a pointplot using Seaborn. Iterate through the plot points and add data labels using annotations. Display the figure using show() method. ...

Read More
Showing 2491–2500 of 61,299 articles
« Prev 1 248 249 250 251 252 6130 Next »
Advertisements