What is the difference between Conv1D and Conv2D? I was going through the keras convolution docs and I have found two types of convultuion Conv1D and Conv2D. I did some web search and this is what I understands about Conv1D and Conv2D; Conv1D is used for sequences  and Conv2D uses for images.
I always thought convolution nerual networks were used only for images and visualized CNN this way

A image is considered as a large matrix and then a filter will slide over this matrix and compute the dot product. This I believe what keras mentions as a Conv2D. If Conv2D works this way then what is the mechanism of Conv1D and how we can imagine its mechanism?
 A: I will be using a Pytorch perspective, however, the logic remains the same.
When using Conv1d(), we have to keep in mind that we are most likely going to work with 2-dimensional inputs such as one-hot-encode DNA sequences or black and white pictures.
The only difference between the more conventional Conv2d() and Conv1d() is that latter uses a 1-dimensional kernel as shown in the picture below.

In here, the height of your input data becomes the “depth” (or in_channels), and our rows become the kernel size. 
For example,
import torch
import torch.nn as nn

tensor = torch.randn(1,100,4)
output = nn.Conv1d(in_channels =100,out_channels=1,kernel_size=1,stride=1)(tensor)
#output.shape == [1,1,4]

We can see that the kernel automatically spans to the height of the picture (just as in Conv2d() the depth of the kernel automatically spans the image’s channels) and therefore all we are left to give is the kernel size with respect to the span of the rows.
We just have to remember that if we are assuming a 2-dimensional input, our filters become our columns and our rows become the kernel size.
A: Convolution is a mathematical operation where you "summarize" a tensor or a matrix or a vector into a smaller one. If your input matrix is one dimensional then you summarize along that on dimensions, and if a tensor has n dimensions then you could summarize along all n dimensions. Conv1D and Conv2D summarize (convolve) along one or two dimensions.
For instance, you could convolve a vector into a shorter vector as followss. Get a "long" vector A with n elements and convolve it using the a weight vector W with m elements into a "short" (summary) vector B with n-m+1 elements:
$$b_i=\sum_{j=m-1}^0 a_{i+j}*w_j$$
where $i=[1,n-m+1]$
So, if you have vector of length n, and your weight matrix is also length n $w_i=1/n$, then the convolution will produce a scalar or a vector of length 1 equal to the average value of all values in the input matrix. It's a sort of degenerate convolution if you wish. If the same weight matrix is one shorter than the input matrix, then you get a moving average in the output of length 2 etc.
$$\begin{bmatrix}
a:&a_1 & a_2 & a_3\\
w:&1/2 & 1/2&\\
w:&&1/2 & 1/2\\
\end{bmatrix}=\begin{bmatrix}
b:&\frac{a_1+a_2} 2
&
\frac{a_2+a_3} 2
\end{bmatrix}
$$
You could do the same to 3 dimensional tensor (matrix) the same way:
$$b_{ikl}=\sum_{j_1=m_1-1\\j_2=m_2-1\\j_3=m_4-1}^{0} a_{i+j_1,k+j_2,l+j_3}*w_{j_1j_2j_3}$$
where $i=[1,n_1-m_1+1],k=[1,n_2-m_2+1],l=[1,n_3-m_3+1]$
A: In summary, In 1D CNN, kernel moves in 1 direction. Input and output data of 1D CNN is 2 dimensional. Mostly used on Time-Series data.
In 2D CNN, kernel moves in 2 directions. Input and output data of 2D CNN is 3 dimensional. Mostly used on Image data.
In 3D CNN, kernel moves in 3 directions. Input and output data of 3D CNN is 4 dimensional. Mostly used on 3D Image data (MRI, CT Scans).
You can find more details here: https://medium.com/@xzz201920/conv1d-conv2d-and-conv3d-8a59182c4d6
A: This 1d convolution is cost saver, it work in the same way but assume a 1 dimension array that makes a multiplication with the elements. If you want to visualize think of a matrix of either row or columns i.e a single dimension when we multiplies we get an array of same shape but of lower or higher values, thus it helps in maximizing or minimizing the intensity of values.
This image might help you,

For details refer,
https://www.youtube.com/watch?v=qVP574skyuM
