Apply 2D Convolution Operation in PyTorch

Shahid Akhtar Khan
Updated on 25-Jan-2022 06:59:37

8K+ Views

We can apply a 2D convolution operation over an input image composed of several input planes using the torch.nn.Conv2d() module. It is implemented as a layer in a convolutional neural network (CNN). The input to a 2D convolution layer must be of size [N, C, H, W] where N is the batch size, C is the number of channels, H and W are the height and width of the input tensor.Generally a 2D convolution operation is applied on the image tensors. For an RGB image, the number of channels is 3. The main feature of a convolution operation is the ... Read More

Discrete Time Fourier Transform

Manish Kumar Saini
Updated on 25-Jan-2022 05:51:31

39K+ Views

Discrete-Time Fourier TransformA discrete-time signal can be represented in the frequency domain using discrete-time Fourier transform. Therefore, the Fourier transform of a discretetime sequence is called the discrete-time Fourier transform (DTFT).Mathematically, if $\mathit{x}\mathrm{\left(\mathit{n}\right)}$ is a discrete-time sequence, then its discrete-time Fourier transform is defined as −$$\mathrm{\mathit{F}\mathrm{\left[\mathit{x}\mathrm{\left(\mathit{n }\right)}\right]}\:\mathrm{=}\:\mathit{X}\mathrm{\left(\mathit{\omega}\right)}\:\mathrm{=}\:\sum_{\mathit{n=-\infty}}^{\infty}\mathit{x}\mathrm{\left(\mathit{n}\right)}\mathit{e^{-\mathit{j\omega n}}}}$$The discrete-time Fourier transform X(ω) of a discrete-time sequence $\mathit{x}\mathrm{\left(\mathit{n}\right)}$ represents the frequency content of the sequence $\mathit{x}\mathrm{\left(\mathit{n}\right)}$. Therefore, by taking the Fourier transform of the discrete-time sequence, the sequence is decomposed into its frequency components. For this reason, the DTFT X(ω) is also called the signal spectrum.Condition for Existence of Discrete-Time Fourier ... Read More

Time Shifting and Frequency Shifting in Discrete Time Fourier Transform

Manish Kumar Saini
Updated on 25-Jan-2022 05:38:27

15K+ Views

Discrete-Time Fourier TransformThe Fourier transform of a discrete-time sequence is known as the discrete-time Fourier transform (DTFT).Mathematically, the discrete-time Fourier transform (DTFT) of a discrete-time sequence $\mathit{x}\mathrm{\left(\mathit{n}\right)}$ is defined as −$$\mathrm{\mathit{F}\mathrm{\left[\mathit{x}\mathrm{\left(\mathit{n }\right)}\right]}\:\mathrm{=}\:\mathit{X}\mathrm{\left(\mathit{\omega}\right)}\:\mathrm{=}\:\sum_{\mathit{n=-\infty}}^{\infty}\mathit{x}\mathrm{\left(\mathit{n}\right)}\mathit{e^{-\mathit{j\omega n}}}}$$Time Shifting Property of Discrete-Time Fourier TransformStatement - The time-shifting property of discrete-time Fourier transform states that if a signal $\mathit{x}\mathrm{\left(\mathit{n}\right)}$ is shifted by k in time domain, then its DTFT is multiplied by $\mathit{e^{-j\omega k }}$. Therefore, if$$\mathrm{\mathit{x}\mathrm{\left(\mathit{n}\right)}\overset{\mathit{FT}}{\leftrightarrow}\mathit{X}\mathrm{\left(\mathit{\omega }\right)}}$$Then$$\mathrm{\mathit{x}\mathrm{\left(\mathit{n-k}\right)}\overset{\mathit{FT}}{\leftrightarrow}\mathit{e^{-j\omega k }}\mathit{X}\mathrm{\left(\mathit{\omega }\right)}}$$Where, k is an integer.ProofFrom the definition of discrete-time Fourier transform, we have, $$\mathrm{\mathit{F}\mathrm{\left[\mathit{x}\mathrm{\left(\mathit{n}\right)}\right]}\:\mathrm{=}\:\mathit{X}\mathrm{\left(\mathit{\omega }\right)}\:\mathrm{=}\:\sum_{\mathit{n=-\infty}}^{\infty}\mathit{x}\mathrm{\left(\mathit{n}\right)}\mathit{e^{-\mathit{j\omega n}}}}$$$$\mathrm{\therefore\mathit{F}\mathrm{\left[\mathit{x}\mathrm{\left(\mathit{n-k}\right)}\right]}\:\mathrm{=}\:\sum_{\mathit{n=-\infty}}^{\infty}\mathit{x}\mathrm{\left(\mathit{n-k}\right)}\mathit{e^{-\mathit{j\omega n}}}}$$Substituting $\mathrm{\left(\mathit{n-k}\right)}\:\mathrm{=}\:\mathit{m}$ then $\mathit{n}\:\mathrm{=}\:\mathrm{\left(\mathit{m\mathrm{+}k}\right)}$ in the above summation, we get, ... Read More

Find the Number of Primitive Roots Modulo Prime in C++

sudhir sharma
Updated on 24-Jan-2022 13:34:13

762 Views

In this problem, we are given a prime number N. Our task is to find the number of primitive roots modulo prime.Primitive Root of a number − It is a number (r) smaller than N which has all values of r^x(mod N) different for all X in range [0, n-2].Let’s take an example to understand the problem, Input : N = 5 Output : 2Solution ApproachA simple solution to the problem is based on a trial method. We will check for all numbers from 2 to (N-1) for the conditions with x ranging from [0, n-2] and break if a value ... Read More

Find Number of Points with Neighboring Points in C++

sudhir sharma
Updated on 24-Jan-2022 13:24:34

152 Views

In this problem, we are given N points that lie in a 2D plane. Our task is to find the number of points that have at least 1 point above, below, left or right of it.We need to count all the points that have at least 1 point which satisfies any of the below conditions.Point above it − The point will have the same X coordinate and the Y coordinate is one more than its current value.Point below it − The point will have the same X coordinate and the Y coordinate is one less than its current value.Point left ... Read More

Find the Number of Operations to Make All Array Elements Equal in C++

sudhir sharma
Updated on 24-Jan-2022 13:18:46

401 Views

In this problem, we are given an array arr of size n. Our task is to Find the number of operations required to make all array elements EqualThe operation is defined as distribution of equal weights from the element with maximum weight to all the elements of the array.If it is not possible to make array elements equal, print -1. Let’s take an example to understand the problem,  Input : arr[] = {7, 3, 3, 3} Output : 3ExplanationArray after distribution is {4, 4, 4, 4}Solution ApproachA simple solution to the problem is by finding the largest value of the array. ... Read More

Find the N-th Binary String in Sorted Order in C++

sudhir sharma
Updated on 24-Jan-2022 13:09:51

161 Views

In this problem, we are given a positive number of 1. Our task is to find the Nth binary string in sorted order.We need to find the Nth string in an infinite list of strings created using only two symbols a and b sorted in lexicographical order.The list is −a, b, aa, ab, ba, bb, aaa, aab, aba, …Let’s take an example to understand the problem, Input : N = 8 Output : aabSolution ApproachA simple solution to the problem is by using loops to generate all n strings. And then return the Nth string. This solution does the work ... Read More

Find the Maximum Value Permutation of a Graph in C++

sudhir sharma
Updated on 24-Jan-2022 13:05:33

234 Views

In this problem, we are given a graph of N nodes. Our task is to Find the maximum possible value of the minimum value of the modified array.For the graph we have a permutation of nodes which is the number of induces with minimum 1 node on the left of it sharing a common edge.Let’s take an example to understand the problem, Input : N = 4, edge = {{1, 2}, {2, 3}, {3, 4}, {4, 1}} Output : 3Solution ApproachA simple solution to the problem is by traversing the tree from one node visiting all its adjacent nodes. We ... Read More

Find Maximum Possible Value of Minimum Value of Modified Array in C++

sudhir sharma
Updated on 24-Jan-2022 12:57:38

435 Views

In this problem, we are given an array arr[] of size n and a number S. Our task is to Find the maximum possible value of the minimum value of the modified array.Here, are the rules to modify the array, The difference between the sum of the array elements before and after modification should be S.Negative values in the modified array are not allowed.If the modified array, the minimum values of the array need to be maximized.The modification of the array can be done by increasing or decreasing any element of the array.Using these constraints, we need to find the ... Read More

Maximum Occurrence of Prefix in Array in C++

sudhir sharma
Updated on 24-Jan-2022 12:49:31

258 Views

In this problem, we are given an array of characters all in lowercase. Our task is to Maximum occurrence of prefix in the Array.We need to count the occurrence of non-empty prefixes whose occurrence count is maximum.Let’s take an example to understand the problem, Input : string = “xyyzkxyyzk” Output : 2Solution ApproachThe logic is to visualize that the prefix of an array must always, obviously, contain the first character of the string and so would be its repeating occurrences. And the first character of a string is obviously a prefix with the least number of characters. So the maximum ... Read More

Advertisements