Using pylab.gcf(), we can create a fig variable and can set the fig.canvas.set_window_title('Setting up window title.') window title.StepsUsing gcf() method, get the current figure. If no current figure exists, a new one is created using `~.pyplot.figure()`.Set the title text of the window containing the figure, using set_window_title() method.. Note that this has no effect if there is no window (e.g., a PS backend).ExamplePlease use Ipython and follow the steps given below -In [1]: from matplotlib import pylab In [2]: fig = pylab.gcf() In [3]: fig.canvas.set_window_title('Setting up window title.')OutputRead More
In this program, we will declare two Pandas series and compare their elements. Before we solve the problem, we need to import the Pandas library into our local IDE. This can be done by installing Pandas on our local machine. The command for installing Pandas is −pip install pandasInputSeries1 = [2,4,6,8,10]Series2 = [1,3,5,7,9]AlgorithmStep 1: Define two Pandas series using the Series() function of Pandas library.Step 2: Compare the series using greater than, less than, and equal-to operators.Example Codeimport pandas as pd series1 = pd.Series([2,4,6,8,10]) series2 = pd.Series([1,3,5,7,9]) print("Greater Than: ",series1>series2) print("Less Than: ",series1
To minus one column from another in an R matrix, we first need to read the matrix as a data frame using as.data.frame then find minus the columns using minus sign and accessing the column of the data frame. To understand how it can be done look at the steps in below examples.ExampleConsider the below data frame − Live DemoM1
To sort each row of an R data frame in increasing order, we can use apply function for sorting the columns and then transpose the output. For example, if we have a data frame called df that contains 5 columns then each row of df can be sorted in increasing order by using the command t(apply(df,1,sort)).Example1Consider the below data frame − Live Demox1
To check if a data frame column contains duplicate values, we can use duplicated function along with any. For example, if we have a data frame called df that contains a column ID then we can check whether ID contains duplicate values or not by using the command −any(duplicated(df$ID))Example1Consider the below data frame − Live DemoID
In this problem, we are given two values S and N denoting the speed of stream in Km/h and ratio of time with up and down streams. Our task is to Find speed of man from the speed of stream and ratio of time with up and down streams.Let’s take an example to understand the problem, InputS = 5, N = 2Output15Solution ApproachA simple solution to the problem is by using the mathematical formula for the rowing problems. So, let’s see how the formula will work −speed of man = x km/h speed of stream = S km/h speed of ... Read More
In this problem, we are given a large number N. Our task is to find the smallest permutation of a given number.Let’s take an example to understand the problem, InputN = 4529016Output1024569Solution ApproachA simple solution to the problem is by storing the long integer value to a string. Then we will sort the string which is our result. But if there are any leading zeros, we will shift them after the first non zero value.Program to illustrate the working of our solution, Example Live Demo#include using namespace std; string smallestNumPer(string s) { int len = s.length(); sort(s.begin(), s.end()); ... Read More
In this problem, we are given two values that are the sum (denoting the sum of digits) and digit (denoting the number of digits). Our task is to find the smallest number with a given number of digits and sum of digits.Let’s take an example to understand the problem, Inputsum = 15, dgiti = 2Output69ExplanationAll 2 digits numbers with sum 15 are : 69, 78, 87, 96.Solution ApproachA simple solution to the problem is by considering all the numbers with digit count as digit and find the smallest number whose sum of digit is equal to the sum.An efficient solution ... Read More
In this problem, we are given a singly linked list. Our task is to find the smallest and largest elements in single linked list.Let’s take an example to understand the problem, Inputlinked List : 5 -> 2 -> 7 -> 3 ->9 -> 1 -> 4OutputSmallest element = 1 Largest element = 9Solution ApproachA simple solution to the problem is using by traversing the linked list node by node. Prior to this, we will initialise maxElement and minElement to the value of the first element i.e. head -> data. Then we will traverse the linked list element by element. And ... Read More
In this problem, we are given a square matrix of size nXn. Our task is to Find smallest and largest element from square matrix diagonals. We need to find the smallest and largest elements of the primary and secondary diagonals of the matrox.Let’s take an example to understand the problem, Inputmat[][] = { {3, 4, 7}, {5, 2, 1}, {1, 8, 6} }OutputSmallest element in Primary Diagonal = 2 Largest element in Primary Diagonal = 6 Smallest element in Secondary Diagonal = 1 Largest element in Secondary Diagonal = 7Solution ApproachA simple solution to solve the problem ... Read More