Programming Articles - Page 690 of 3366

Python – numpy.reshape

Syed Abeed
Updated on 03-Mar-2022 07:19:58

502 Views

numpy.reshape() gives a new shape to an array without changing its data. Its syntax is as follows −numpy.reshape(arr, newshape, order='C')Parametersnumpy.reshape() can accept the following parameters −arr − Input array.shape − endpoint of the sequencenewshape − If an integer, then the result it will be a 1-D array of that length, and one dimension can be -1.order − It defines the order in which the input array elements should be read.If the order is ‘C’, then it reads and writes the elements which are using a C-like index order where the last index changes the fastest and the first axis index ... Read More

C++ program to convert kth character to lowercase

Arnab Chakraborty
Updated on 03-Mar-2022 07:15:49

216 Views

Suppose we have a string S with N characters. S contains only three types of characters 'A', 'B' or 'C'. We also have another integer K. We have to print S after lowercasing the Kth character in it.So, if the input is like K = 2; S = "AABACC", then the output will be "AaBACC"StepsTo solve this, we will follow these steps −S[K - 1] = S[K - 1] + 32 return SExampleLet us see the following implementation to get better understanding −#include using namespace std; string solve(int K, string S){    S[K - 1] = S[K - ... Read More

C++ program to find string after adding character 'a' string becomes non-palindrome

Arnab Chakraborty
Updated on 03-Mar-2022 07:17:30

161 Views

Suppose we have a string S with lowercase English letters. We must insert exactly one character 'a' in S. After inserting that if we can make S not a palindrome then return that string, otherwise return "impossible".So, if the input is like S = "bpapb", then the output will be "bpaapb"StepsTo solve this, we will follow these steps −if concatenation of S and "a" is not palindrome, then:    return S concatenation 'a' otherwise when concatenation of "a" + S is not palindrome, then:    return 'a' concatenation S Otherwise    return "Impossible"ExampleLet us see the following implementation to get ... Read More

Python – numpy.geomspace

Syed Abeed
Updated on 03-Mar-2022 07:14:26

555 Views

numpy.geomspace() returns a set of numbers spaced evenly on a log scale (a geometric progression).Linspace − It is similar to geomspace, but endpoints specified using the log and base.Logspace − It is similar to geomspace, but endpoints specified with arithmetic instead of geometric progression.Syntaxnumpy.goemspace(start, stop, num = 50, endpoint = True/False, dtype = None)ParametersThe above function can accept the following parameters −start − Start of the sequence; default is zero.stop − Endpoint of the sequence.num − Number of elements which are generated between the start and stop sequence.endpoint − It controls whether the stop value is included in the output ... Read More

C++ program to find minimum possible difference of largest and smallest of crackers

Arnab Chakraborty
Updated on 03-Mar-2022 07:13:47

335 Views

Suppose we have two numbers N and K. We want to distribute N crackers to K users. We have to find the minimum possible difference between the largest number of crackers received by a user and smallest number received by a user.So, if the input is like N = 7; K = 3, then the output will be 1, because when the users receive two, two and three crackers, respectively, the difference between the largest number of crackers received by a user and the smallest number received by a user, is 1.StepsTo solve this, we will follow these steps −if ... Read More

Python – numpy.logspace

Syed Abeed
Updated on 03-Mar-2022 07:11:59

410 Views

numpy.logspace returns a set of numbers spaced evenly on a log scale. Its syntax is as follows −numpy.logspace(start, stop, num = 50, endpoint = True/False, base = 10.0, dtype = None)ParametersThe logspace function can accept the following parameters −start − Start of the sequence; default is zero.stop − Endpoint of the sequence.num − Number of elements to be generated between the start and stop sequence.endpoint − It controls whether the stop value is included in the output array or not. If the endpoint is True, then the stop parameter is included as the last item in the nd.array. If endpoint=false, ... Read More

C++ program to check the coins forms x amount of rupees or not

Arnab Chakraborty
Updated on 03-Mar-2022 07:11:53

165 Views

Suppose we have two numbers K and X. Consider Amal has K, 500 rupee notes. We have to check whether the sums up to X rupees or not.So, if the input is like K = 2; X = 900, then the output will be True, because 2*500 = 1000 and it is not less than 900.StepsTo solve this, we will follow these steps −if (500 * k) >= x, then:    return true Otherwise    return falseExampleLet us see the following implementation to get better understanding −#include using namespace std; bool solve(int k, int x){    if ((500 * k) >= x){       return true;    } else{       return false;    } } int main(){    int K = 2;    int X = 900;    cout

Python – numpy.linspace

Syed Abeed
Updated on 03-Mar-2022 07:05:40

2K+ Views

The numpy.linspace function is used to create a set of evenly spaced numbers within a defined interval.Syntaxnumpy.linspace(start, stop, num = 50, endpoint = True/False, retstep = False/True, dtype = None)ParametersThe function can accept the following parameters −start − Start of the sequence; by default, it is considered as zero.stop − Endpoint of the sequence.num − Number of elements to be generated between start and stop.endpoint − It controls whether the stop value is included in the output array or not. If the endpoint is True, then the stop parameter is included as the the last item in the nd.array. If ... Read More

C++ program to count in how many ways we can minimize cable length to connect computers

Arnab Chakraborty
Updated on 03-Mar-2022 07:02:43

311 Views

Suppose we have two arrays A and B both with N elements. Consider there are N computers and N sockets. The coordinate of ith computer is A[i] and coordinate of ith socket is b[i]. These 2N coordinates are pair-wise distinct. We want to connect each computer with a socket by cables. Each socket can be connected at most one computer. We have to count in how many ways we can minimize the length of cables. If the answer is too large, return result mod 10^9 + 7.So, if the input is like A = [0, 10]; B = [20, 30], ... Read More

C++ program to check whether we can distribute bags so that two friends will get same amount of candies

Arnab Chakraborty
Updated on 03-Mar-2022 07:01:58

242 Views

Suppose we have an array A with 4 elements. There are 4 bags of candies, ith bag contains A[i] amount of candies. We want to give each bags to one of our two friends. We have to check whether we can distribute these bags in such a way that each friend receives the same amount of candies in total?So, if the input is like A = [1, 7, 11, 5], then the output will be True, because we can give the first and the third bag to the first friend, and the second and the fourth bag to the second ... Read More

Advertisements