Programming Articles

Page 228 of 2545

How to find the absolute maximum of a matrix with sign if it contains negative values in R?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 11-Mar-2026 473 Views

If we have positive as well as negative values in a matrix then the maximum of the matrix will be a positive number but if we want to ignore the sign then a number represented with negative sign can also be the maximum. If we want to get the maximum with its sign then which.max function can be used in R. Check out the below examples to understand how to do it.ExampleM1

Read More

How can SciPy be used to calculate the permutations and combination values in Python?

AmitDiwan
AmitDiwan
Updated on 11-Mar-2026 737 Views

SciPy can be used to determine the permutation and combination with respect to two values.A function named ‘perm’ present in the class ‘special’ in ‘SciPy’ is used.Syntax of ‘perm’ functionscipy.special.perm(N, k)Performing permutation on a set of values has been shown belowExamplefrom scipy.special import perm my_permute = perm(6, 2, exact = True) print("The permutation of 6 and 2 is ") print(my_permute)OutputThe permutation of 6 and 2 is 30ExplanationThe required libraries are imported.Parameters are passed to the ‘perm’ function that computes the value.The value is assigned to a variable.This variable is displayed on the console.Computing combination of two values in SciPyA function ...

Read More

Check if the given array can be reduced to zeros with the given operation performed given number of times in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Mar-2026 182 Views

Suppose we have an array nums and a value k, we have to check whether the elements in nums can be made 0 by performing the following operation exactly k number of times or not.Operation: The smallest element from the nums will be subtracted from all of the non-zero values of nums.So, if the input is like nums [2, 2, 3, 5] k = 3, then the output will be True because at first delete 2 from array, so the array will be [0, 0, 1, 3], then remove 1 to get [0, 0, 0, 2], then again delete 2 ...

Read More

How to create a column with the serial number of values in character column of an R data frame?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 11-Mar-2026 1K+ Views

A group column in an R data frame have duplicate values and we might want to create a column with the serial number based on the values such as first value of the first group gets 1, the same value gets 2 when occurred second time in the same column and so on. This can be done by using ave function as shown in the below examples.ExampleConsider the below data frame −S.No

Read More

Check if the given array contains all the divisors of some integer in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Mar-2026 144 Views

Suppose we have an array nums, we have to check whether this array is containing all of the divisors of some integer or not.So, if the input is like nums = [1, 2, 3, 4, 6, 8, 12, 24], then the output will be True as these are the divisors of 24.To solve this, we will follow these steps −maximum := maximum of numstemp := a new listfor i in range 1 to square root of maximum, doif maximum is divisible by i, theninsert i at the end of tempif quotient of (maximum / i) is not same as i, ...

Read More

How to find the mean of three-dimensional array in R?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 11-Mar-2026 1K+ Views

A three-dimensional array can have matrices of different size and they are not necessarily to be square or rectangular. Also, all the elements in an array are of same data type. If we want to find the mean of a three-dimensional array then apply function can be used where we need to refer the columns and rows of the array elements using combination function.ExampleA1 apply(A1,c(1,2),mean) [,1] [,2] [1,] 5 7 [2,] 6 8ExampleA2

Read More

Check if the given decimal number has 0 and 1 digits only in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Mar-2026 613 Views

Suppose we have a number num. We have to check whether num is consists of only 0s and 1s or not.So, if the input is like num = 101101, then the output will be True.To solve this, we will follow these steps −digits_set := a new set with all elements digits of numdelete 0 from digits_setdelete 1 from digits_setif size of digits_set is same as 0, thenreturn Truereturn FalseLet us see the following implementation to get better understanding −Example Codedef solve(num):    digits_set = set()    while num > 0:       digit = num % 10   ...

Read More

How to create a rectangle inside boxplot in base R?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 11-Mar-2026 300 Views

To create a rectangle inside boxplot in base R, we can use rect function after creating the boxplot. The rect function has many arguments but for the creation of a rectangle only first four are necessary and these are defined as xleft - a vector (or scalar) of left x positions, ybottom - a vector (or scalar) of bottom y positions, xright - a vector (or scalar) of right x positions and ytop - a vector (or scalar) of top y positions.Examplex

Read More

Check if the given number is Ore number or not in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Mar-2026 383 Views

Suppose we have a number n. We have to check whether n is an ore number or not. As we know an ore number is a number whose divisors have an integer harmonic value.So, if the input is like 28, then the output will be True as there are six divisors of 28: [1, 2, 4, 7, 14, 28], soAs 3 is an integer so 28 is an ore number.To solve this, we will follow these steps −Define a function get_all_div() . This will take ndiv := a new listfor i in range 1 to integer part of (square root ...

Read More

How to create a table of sums of a discrete variable for two categorical variables in an R data frame?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 11-Mar-2026 555 Views

If we want to create a table of sums of a discrete variable for two categorical variables then xtabs function can be used. The output will be a contingency table or cross tabulation table which looks like a matrix. For example, if we have a data frame df with two categorical column x and y and a count column freq then the table of sums for freq can be created by using xtabs(freq~x+y,data=df1).ExampleConsider the below data frame −x1

Read More
Showing 2271–2280 of 25,445 articles
« Prev 1 226 227 228 229 230 2545 Next »
Advertisements