Lua/torch multiplication of 1D and 2D tensors - matrix

I am trying to multiply two matrices in lua whose dimensions are a=40,000x1 and b=1x40,000. In Lua, the 40,000x1 matrix is showing up as a 1D tensor and the 1x40,000 matrix is showing up as a 2D tensor. Whenever, I try to multiply them simply using a*b, an error is showing up: multiplication between 1D and 2D tensors not yet supported. I cannot iteratively go through each index because this function is used regularly in my program and would considerably increase time of execution. How can I multiply a and b?

Use view:
c = a:view(40000, 1) * b

Related

Invertibility / singularity of matrix resulting from a symmetric(0,1) matrix pointwise multiplicated with a vector (consisting of a,b)+identity matrix

I am trying to find conditions then a certain matrix is invertible or not (which is problematic as the matrix is random). The matrix results from the following:
$A=\Tilde{A}+diag(n)$.
Furthermore $\Tilde{A}$ results from the pointwise multiplication of a random symmetric matrix (consisting of 0 and 1, but necessarily 0 on the diagonal) with a random vector which constsis of $\alpha$ and $\beta$ entries.
Does anyone have any ideas how to deduce some criterions for the invertibility of matrix $A$?
Thank you so much!
I already tried thinking about LU decomoposition, but could not deduce any criterion. Obviosly, it fully depends on how the random matrices look and linear dependence between the rows are less likely if the dimension is higher...

How to multiply one matrix by another in order to return a matrix of ones

I have a 20x20 matrix filled with random numbers. I need to find what matrix will multiply with the random one in order to return a 20x1 matrix of all ones.
What I've tried:
inv(A) (where A is a 20x20 matrix filled with random numbers) I know I don't want the inverse of the matrix because, if successful, it would only return the identity matrix, which is not what I need.
I suggest you use matrix algebra to express the problem and derive the solution. Consider the following, where * means matrix multiplication and 1 means the vector of all ones, and Ainv is the inverse matrix for A.
A*x=1
Ainv * A * x = Ainv * 1
x = Ainv * 1
[EDIT 7 MAR 2016]
In many computer algebra systems (MATLAB, scipy, etc.), there is a function called solve (or similar) which can be used to solve linear systems expressed as Ax=b. In particular, for MATLAB, see: linsolve. Also, for MATLAB, see the backslash operator.
I'm a python user, so I use numpy.linalg.solve(), which does the same thing (see this link).

Savitzky–Golay filter for 2D images

I would like to ask about Savitzky–Golay filter on 2D-images.
What are the best coefficient and order to choose for finding local details in the image.
Moreover, if someone has an explanation for coefficients and the orders one the 2D-images, it would be perfect.
Thanks in advance
Please check out this website:
https://en.wikipedia.org/wiki/Savitzky%E2%80%93Golay_filter#Two-dimensional_convolution_coefficients
UPDATE: (Thank you for the suggestion, #Rasclatt)
Which has been reproduced here:
Two-dimensional smoothing and differentiation can also be applied to tables of data values, such as intensity values in a photographic image which is composed of a rectangular grid of pixels.[16] [17] The trick is to transform part of the table into a row by a simple ordering of the indices of the pixels. Whereas the one-dimensional filter coefficients are found by fitting a polynomial in the subsidiary variable, z to a set of m data points, the two-dimensional coefficients are found by fitting a polynomial in subsidiary variables v and w to a set of m × m data points. The following example, for a bicubic polynomial and m = 5, illustrates the process, which parallels the process for the one dimensional case, above.[18]
The square of 25 data values, d1 − d25
becomes a vector when the rows are placed one after another.
The Jacobian has 10 columns, one for each of the parameters a00 − a03 and 25 rows, one for each pair of v and w values. Each row has the form
The convolution coefficients are calculated as
The first row of C contains 25 convolution coefficients which can be multiplied with the 25 data values to provide a smoothed value for the central data point (13) of the 25.
check out the below links which use SURE(Stein's unbiased risk estimator) to minimizes the mean squared error between your estimate and the image. This method is useful for denoising and data smoothing.
this link is for optimization of parameters for 1D Savitzky Golay Filter(this will be helpful to understand the 2D part)
https://ieeexplore.ieee.org/abstract/document/6331560/?part=1
this link is for optimization of parameters of 2D Savitzky Golay Filter
https://ieeexplore.ieee.org/document/6738095/

how to multiply two images in matrix multiplication manner in matlab?

I have two images A and B, each of mxm size. I want to multiply these images such that C=AxB.
So far I've found the immultiply function in MATLAB, but this function multiplies the corresponding bits of the images rather than performing matrix multiplication.
I have also tried A.*B but this also gives multiplication of corresponding bits. When I try A*B I get this message:
??? Error using ==> mtimes
Integer data types are not fully supported for this operation.
At least one operand must be a scalar.
You need to convert the images into doubles before multiplying them.
Example:
multiplied = double(firstMat) * double(secondMat);

sub2ind all x and y coordinates of a matrix

I am a quite newbie on matlab and i have a simple issue that is disturbing me,
I want to know if its possible to covert all the subscripts of a matrix to linear indices.
when using SUB2IND i must inform de x and y coordinates, but i want to convert all at the same time.
i can use function FIND which returns two vectors x and y and this way i can use SUB2IND succesfully, but FIND only returns the x and y coordinates of nonzero elements.
is there a smart way to do this?
If you want all of the elements of an array A as linear subscripts, this can be done simply via:
IND = 1:numel(A);
This works for any size or dimension array.
More on array indexing in Matlab, including the difference between linear indexing and logical indexing. When you use find you're essentially using logical indexing to obtain linear indexing. The find function can be used to reliably obtain all of your linear indices, via IND = find(A==A);, but this is horrendously inefficient.
you don't need to convert, just use a single number \ 1-D vector when accessing elements of your matrix. For example, given a 5x5 matrix M
M=magic(5);
you can access the last element using M(5,5) or using M(25) ...
similarly M(21:25) will give you the info of M(1,5),M(2,5),...M(5,5).

Resources