Found 33676 Articles for Programming

Compute the tensor dot product for arrays with different dimensions over specific axes in Python

AmitDiwan
Updated on 02-Mar-2022 09:28:19

187 Views

Given two tensors, a and b, and an array_like object containing two array_like objects, (a_axes, b_axes), sum the products of a’s and b’s elements (components) over the axes specified by a_axes and b_axes. The third argument can be a single non-negative integer_like scalar, N; if it is such, then the last N dimensions of a and the first N dimensions of b are summed over.To compute the tensor dot product for arrays with different dimensions, use the numpy.tensordot() method in Python. The a, b parameters are Tensors to “dot”.The axes parameter, integer_like If an int N, sum over the last ... Read More

C++ program to find out the maximum number of cells that can be illuminated

Arnab Chakraborty
Updated on 02-Mar-2022 09:38:22

263 Views

Suppose, we are given a grid of dimensions h * w. The cells in the grid can contain either a bulb or obstacles. A light bulb cell illuminates the cells in its right, left, up, and down and the light can shine through the cells unless an obstacle cell blocks the light. An obstacle cell can not be illuminated and it blocks the light from a bulb cell from reaching the other cells. We are given the grid in an array of strings, where '#' represents an obstacle and '.' represents a vacant cell. We have only one bulb and ... Read More

C++ Program to find out the number of illuminated cells in a grid

Arnab Chakraborty
Updated on 02-Mar-2022 08:12:53

215 Views

Suppose, we are given a grid of dimensions h * w. The cells in the grid can contain either bulbs or obstacles. A light bulb cell illuminates itself and the cells in its right, left, up, and down and the light can shine through the cells unless an obstacle cell blocks the light. An obstacle cell can not be illuminated and it blocks the light from a bulb cell from reaching the other cells. So, given the position of the bulb cells in the grid in array 'bulb' and the position of obstacle cells in the array 'obstacles', we have ... Read More

Return rank of a Full Rank matrix using Singular Value Decomposition method in Python

AmitDiwan
Updated on 02-Mar-2022 09:26:06

473 Views

To return matrix rank of array using Singular Value Decomposition method, use the numpy.linalg.matrix_rank() method in Python. Rank of the array is the number of singular values of the array that are greater than tol. The 1st parameter, A is the input vector or stack of matrices.The 2nd parameter, tol is the Threshold below which SVD values are considered zero. If tol is None, and S is an array with singular values for M, and eps is the epsilon value for datatype of S, then tol is set to S.max() * max(M, N) * eps. The 3rd parameter, hermitian, If ... Read More

C++ Program to find out the number of bridge edges in a given graph

Arnab Chakraborty
Updated on 02-Mar-2022 08:05:16

483 Views

Suppose, we are given an unweighted, undirected graph that contains n vertices and m edges. A bridge edge in a graph is an edge whose removal causes the graph to be disconnected. We have to find out the number of such graphs in a given graph. The graph does not contain parallel edges or self-loops.So, if the input is like n = 5, m = 6, edges = {{1, 2}, {1, 3}, {2, 3}, {2, 4}, {2, 5}, {3, 5}}, then the output will be 1.The graph contains only one bridge edge that is {2, 4}.To solve this, we will ... Read More

Return the cumulative product treating NaNs as one but change the type of result in Python

AmitDiwan
Updated on 02-Mar-2022 08:00:29

148 Views

To return the cumulative product of array elements over a given axis treating NaNs as one, use the nancumprod() method. The cumulative product does not change when NaNs are encountered and leading NaNs are replaced by ones. Ones are returned for slices that are all-NaN or empty.The method returns a new array holding the result is returned unless out is specified, in which case it is returned. Cumulative works like, 5, 5*10, 5*10*15, 5*10*15*20. The 1st parameter is the input array. The 2nd parameter is the Axis along which the cumulative product is computed. By default the input is flattened.The ... Read More

Return the cumulative product of array elements over axis 1 treating NaNs as one in Python

AmitDiwan
Updated on 02-Mar-2022 07:55:22

124 Views

To return the cumulative product of array elements over a given axis treating NaNs as one, use the nancumprod() method. The cumulative product does not change when NaNs are encountered and leading NaNs are replaced by ones. Ones are returned for slices that are all-NaN or empty. The method returns a new array holding the result is returned unless out is specified, in which case it is returned.Cumulative works like, 5, 5*10, 5*10*15, 5*10*15*20. The 1st parameter is the input array. The 2nd parameter is the Axis along which the cumulative product is computed. By default the input is flattened. ... Read More

C++ Program to find out the number of sides that a polygon has inside a grid

Arnab Chakraborty
Updated on 02-Mar-2022 12:55:32

481 Views

Suppose, we are given a grid of dimensions h x w. There are two types of cells in the grid, white and black cells. White cells are represented by '.', whereas black cells are represented by '#'. Now the grid has multiple black cells in it that form a polygon. We have to find out the number of sides that the polygon has. It is to be noted, that the outermost cells of the grid are always white.So, if the input is like h = 4, w = 4, grid = {"....", ".##.", ".##.", "...."}, then the output will be ... Read More

Compute the tensor dot product for arrays with different dimensions in Python

AmitDiwan
Updated on 02-Mar-2022 07:51:46

617 Views

Given two tensors, a and b, and an array_like object containing two array_like objects, (a_axes, b_axes), sum the products of a’s and b’s elements (components) over the axes specified by a_axes and b_axes. The third argument can be a single non-negative integer_like scalar, N; if it is such, then the last N dimensions of a and the first N dimensions of b are summed over.To compute the tensor dot product for arrays with different dimensions, use the numpy.tensordot() method. The a, b parameters are Tensors to “dot”. The axes parameter, integer_like If an int N, sum over the last N ... Read More

C++ program to find out the number of pairs in an array that satisfy a given condition

Arnab Chakraborty
Updated on 02-Mar-2022 07:50:50

2K+ Views

Suppose, we are given n numbers in array nums. We have to choose a pair of two numbers from the array, and there is a condition that the difference of their positions in the array is equal to the sum of the two numbers. There can be a total of n(n - 1)/2 number of total pairs from the given array of numbers. We have to find out the total number of such pairs from the array.So, if the input is like n = 8, nums = {4, 2, 1, 0, 1, 2, 3, 3}, then the output will be ... Read More

Advertisements