Server Side Programming Articles - Page 1695 of 2650

Python - Filter out integers from float numpy array

Pradeep Elance
Updated on 22-Jul-2020 08:36:16

521 Views

As part of data cleansing activities, we may sometimes need to take out the integers present in a list. In this article we will have an array containing both floats and integers. We will remove the integers from the array and print out the floats.With astypeThe astype function will be used to find if an element from the array is an integer or not. Accordingly we will decide to keep or remove the element from the array and store it in the result set.Example Live Demoimport numpy as np # initialising array A_array = np.array([3.2, 5.5, 2.0, 4.1, 5]) ... Read More

Python - Filter dictionary key based on the values in selective list

Pradeep Elance
Updated on 22-Jul-2020 08:34:33

2K+ Views

Sometimes in a Python dictionary we may need to to filter out certain keys of the dictionary based on certain criteria. In this article we will see how to filter out keys from Python dictionary.With for and inIn this approach we put the values of the keys to be filtered in a list. Then iterate through each element of the list and check for its presence in the given dictionary. We create a resulting dictionary containing these values which are found in the dictionary.Example Live DemodictA= {'Mon':'Phy', 'Tue':'chem', 'Wed':'Math', 'Thu':'Bio'} key_list = ['Tue', 'Thu'] print("Given Dictionary:", dictA) print("Keys for filter:", ... Read More

Python - fabs() vs abs()

Pradeep Elance
Updated on 22-Jul-2020 08:32:37

1K+ Views

Both abs() and fabs() represent the mathematical functions which give us the absolute value of numbers. But there is a subtle difference between both of them which we can explore in the exmaples below.ExampleThe abs() functions returns the absolute value as an integer or floating point value depending on what value was supplied dot it. But the fabs) function will always return the value as floating point irrespective of whether an integer or a floating point was supplied to it as a parameter. Live Demoimport math n = -23 print(abs(n)) print(math.fabs(n)) n = 21.4 print(abs(n)) print(math.fabs(n)) n = ... Read More

Maximum sum of elements from each row in the matrix in C++

Ayush Gupta
Updated on 15-Oct-2020 12:11:37

915 Views

In this problem, we are given a two matrix mat[][]. Our task is to create a program to find the maximum sum of elements from each row in the matrix in C++.Problem DescriptionHere, we will find the maximum sum by taking one element from each row of the matrix in such a way that the element at the current row is greater than the last row element to be considered as a sum. We will find the maximum sum of elements that follows the above condition and print -1 if it is not possible.Let’s take an example to understand the ... Read More

Maximum sum of distinct numbers with LCM as N in C++

Revathi Satya
Updated on 22-May-2024 11:56:22

353 Views

In this article, we are given a number N. Our task is to create a program to find the maximum sum of distinct numbers with LCM as N in C++. To achive this first of all we need to find the sum of maximum numbers that have N as the Lowest Common Multiple (LCM). For better understanding Let us go through 3 key concepts − Least Common Multiple (LCM): The lowest common multiple(LCM) of two or more integers is the smallest positive integer that is divisible for all of the integers. For example, the LCM of 4 and 5 ... Read More

Maximum sum of distinct numbers such that LCM of these numbers is N in C++

Ayush Gupta
Updated on 15-Oct-2020 12:16:27

195 Views

In this problem, we are a number N. Our task is to create a program to find the Maximum sum of distinct numbers such that LCM of these numbers is N in C++.Problem DescriptionWe need to find the sum of all factors of the number N. And add all distinct to find the maximum sum.Let’s take an example to understand the problem, InputN = 12Output28ExplanationAll distinct factors of N are 1, 2, 3, 4, 6, 12. Sum = 1 + 2 + 3 + 4 + 6 + 12 = 28Solution ApproachA simple solution will be finding all the factors ... Read More

Maximum sum of difference of adjacent elements in C++

Ayush Gupta
Updated on 15-Oct-2020 12:17:54

339 Views

In this problem, we are given a number N. Our task is to create a program to find the Maximum sum of difference of adjacent elements in C++.Problem DescriptionWe will find the Maximum sum of the absolute difference between the adjacent elements of all permutation arrays.Let’s take an example to understand the problem, InputN = 4Output7ExplanationAll permutations of size 4 are : {1, 2, 3, 4} = 1 + 1 + 1 = 3 {1, 2, 4, 3} = 1 + 2 + 1 = 4 {1, 3, 2, 4} = 2 + 1 + 2 = 5 {1, 3, ... Read More

Python - end parameter in print()

Pradeep Elance
Updated on 22-Jul-2020 08:30:56

1K+ Views

The print() function in python always creates a newline. But there is also a parameter for this function which can put other characters instead of new line at the end. In this article we will explore various options for this parameter.ExampleIn the below example we see various ways we can assign values to the end parameter and see the result from it. Live Demoprint("Welcome to ") print("Tutorialspoint") print("Welcome to ", end = ' ') print("Tutorialspoint") print("emailid", end='@') print("tutorialspoint.com")OutputRunning the above code gives us the following result −Welcome to Tutorialspoint Welcome to Tutorialspoint emailid@tutorialspoint.comRead More

Maximum sum of absolute difference of any permutation in C++

Ayush Gupta
Updated on 15-Oct-2020 12:19:26

643 Views

In this problem, we are given an array. Our task is to create a program to find the Maximum sum of absolute difference of any permutation in C++.Problem DescriptionWe will be finding all permutation of the elements of the given array. And then finding the sum of the absolute difference of adjacent elements of the array. Lastly we will return the maximum of all sums.Let’s take an example to understand the problem, Inputarr[] = {9, 1, 6, 3}Output17ExplanationAll permutations of the array with sum of absolute difference of adjacent elements. {9, 1, 6, 3}, sum= |9-1| + |1-6| + |6-3| ... Read More

Maximum Sum Increasing Subsequence using Binary Indexed Tree in C++

Ayush Gupta
Updated on 15-Oct-2020 12:21:46

153 Views

In this problem, we are given an array arr[] of N elements. Our task is to create a program to find the maximum Sum Increasing Subsequence using Binary Indexed Tree in C++.Let’s take an example to understand the problem, Inputarr[] = {4, 1, 9, 2, 3, 7}Output13ExplanationMaximum increasing subsequence is 1, 2, 3, 7. Sum = 13Solution ApproachTo solve the problem, we will use the Binary Indexed Tree in which we will insert values and map them to binary indexed tree. Then find the maximum value.ExampleProgram to illustrate the working of our solution,  Live Demo#include using namespace std; int ... Read More

Advertisements