Found 33676 Articles for Programming

Change figure window title in pylab(Python)

Rishikesh Kumar Rishi
Updated on 16-Mar-2021 10:07:24

3K+ Views

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

Python program to compare two Pandas series

Prasad Naik
Updated on 16-Mar-2021 09:55:48

604 Views

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

How to convert negative values in a matrix to 0 in R?

Nizamuddin Siddiqui
Updated on 16-Mar-2021 10:10:24

5K+ Views

To convert negative values in a matrix to 0, we can use pmax function. For example, if we have a matrix called M that contains some negative and some positive and zero values then the negative values in M can be converted to 0 by using the command pmax(M,0).ExampleConsider the below data frame − Live DemoM1

How to minus one column from another in an R matrix?

Nizamuddin Siddiqui
Updated on 16-Mar-2021 07:44:09

6K+ Views

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

How to sort each row of an R data frame in increasing order?

Nizamuddin Siddiqui
Updated on 16-Mar-2021 07:35:06

2K+ Views

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

How to check if a data frame column contains duplicate values in R?

Nizamuddin Siddiqui
Updated on 16-Mar-2021 07:25:26

2K+ Views

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

Find speed of man from speed of stream and ratio of time with up and down streams in C++

sudhir sharma
Updated on 16-Mar-2021 06:41:00

154 Views

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

Find smallest permutation of given number in C++

sudhir sharma
Updated on 16-Mar-2021 06:38:31

836 Views

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

Find smallest number with given number of digits and sum of digits in C++

sudhir sharma
Updated on 16-Mar-2021 06:37:29

1K+ Views

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

Find smallest and largest elements in singly linked list in C++

sudhir sharma
Updated on 16-Mar-2021 06:35:28

896 Views

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

Advertisements