Articles on Trending Technologies

Technical articles with clear explanations and examples

Program to find out the sum of numbers where the correct permutation can occur in python

Arnab Chakraborty
Arnab Chakraborty
Updated on 26-Mar-2026 429 Views

Given a number n, we need to find all possible permutations of positive integers up to n, sort them lexicographically, and number them from 1 to n!. When some values in a "special permutation" are forgotten (replaced with 0s), we must find all permutations that could match the original and sum their lexicographic positions. For example, if the special permutation is [0, 2, 0] with n=3, the possible original permutations are [1, 2, 3] (position 2) and [3, 2, 1] (position 5), giving us a sum of 7. Algorithm Steps The solution uses factorial number system and ...

Read More

Matplotlib – How to show the coordinates of a point upon mouse click?

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

In Matplotlib, you can capture mouse click coordinates on a plot by connecting an event handler to the figure's canvas. This is useful for interactive data exploration and annotation. Setting Up Mouse Click Detection The key is to use mpl_connect() to bind a function to the 'button_press_event' ? import numpy as np import matplotlib.pyplot as plt plt.rcParams["figure.figsize"] = [7.00, 3.50] plt.rcParams["figure.autolayout"] = True def mouse_event(event): if event.xdata is not None and event.ydata is not None: print('x: {:.3f} and y: {:.3f}'.format(event.xdata, event.ydata)) ...

Read More

How to read an input image and print it into an array in matplotlib?

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

To read an input image and print it into an array in matplotlib, we can use plt.imread() to load the image as a NumPy array and plt.imshow() to display it. Steps Import matplotlib.pyplot Read an image from a file using plt.imread() method Print the NumPy array representation of the image Display the image using plt.imshow() Use plt.axis('off') to hide axis labels Show the plot using plt.show() Example with Sample Data ...

Read More

Program to determine the minimum cost to build a given string in python

Arnab Chakraborty
Arnab Chakraborty
Updated on 26-Mar-2026 1K+ Views

Suppose we have to build a string str of length n. To build the string, we can perform two operations: Add a character to the end of str for cost a Add a substring that already exists in the current string for cost r We need to calculate the minimum cost of building the string str using dynamic programming. Example If the input is a = 5, r = 4, str = 'tpoint', then the output will be 29. To build the string 'tpoint', the ...

Read More

How to create minor ticks for a polar plot in matplotlib?

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

To create minor ticks for a polar plot in matplotlib, you can manually draw tick marks at specified angular positions. This technique is useful when you need more granular control over tick positioning than the default matplotlib settings provide. Basic Approach The process involves creating radial lines at specific angles to simulate minor ticks. Here's how to implement it ? import numpy as np import matplotlib.pyplot as plt # Set the figure size plt.rcParams["figure.figsize"] = [7.00, 3.50] plt.rcParams["figure.autolayout"] = True # Create radius and theta data points r = np.arange(0, 5, 0.1) theta = ...

Read More

How to plot an animated image matrix in matplotlib?

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

To plot an animated image matrix in matplotlib, we can use FuncAnimation to repeatedly update a matrix display. This creates smooth animated visualizations of changing data patterns. Steps Set the figure size and adjust the padding between and around the subplots. Create a figure and a set of subplots. Make an animation by repeatedly calling a function update. Inside the update method, create a 6×6 dimension of matrix and display the data as an image, i.e., on a 2D regular raster. Turn off the axes using set_axis_off(). To display the figure, use show() method. Basic ...

Read More

How to put xtick labels in a box matplotlib?

Rishikesh Kumar Rishi
Rishikesh Kumar Rishi
Updated on 26-Mar-2026 785 Views

To put xtick labels in a box in matplotlib, we use the set_bbox() method on tick label objects. This creates a visible box around each x-axis label with customizable styling. Steps Create a new figure or activate an existing figure Get the current axis of the figure Position the spines and ticks as needed Iterate through the x-tick labels using get_xticklabels() Apply set_bbox() method with desired box properties Display the figure using show() method Basic Example Here's how to add boxes around x-tick labels ? import matplotlib.pyplot as plt import numpy as ...

Read More

Program to find maximum score by splitting binary strings into two parts in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 26-Mar-2026 485 Views

Suppose we have a binary string s. We need to split it into two non-empty substrings s1 and s2. The score of this split is the count of "0"s in s1 plus the count of "1"s in s2. We have to find the maximum score we can obtain. So, if the input is like s = "011001100111", then the output will be 8, because we can split the string like "01100" + "1100111". Then, the score is 3 + 5 = 8. Algorithm To solve this, we will follow these steps − ones := number ...

Read More

How to plot a time as an index value in a Pandas dataframe in Matplotlib?

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

To plot a time as an index value in a Pandas DataFrame using Matplotlib, you need to set the time column as the DataFrame index. This allows the time values to appear on the x−axis automatically when plotting. Steps Create a DataFrame with time and numeric data columns Convert the time column to datetime format if needed Set the time column as the DataFrame index using set_index() Use the DataFrame's plot() method to create the visualization Basic Time Series Plot Here's how to create a simple time series plot with time as the index ...

Read More

Program to find matrix for which rows and columns holding sum of behind rows and columns in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 26-Mar-2026 274 Views

Given a matrix, we need to find a new matrix where each element at position res[i, j] contains the sum of all elements from the original matrix where row r ≤ i and column c ≤ j. This is known as calculating the prefix sum matrix or cumulative sum matrix. Problem Understanding For each position (i, j) in the result matrix, we sum all elements in the rectangle from (0, 0) to (i, j) in the original matrix. If the input matrix is ? 8 2 7 4 Then ...

Read More
Showing 3191–3200 of 61,299 articles
« Prev 1 318 319 320 321 322 6130 Next »
Advertisements