I can send the row of a matrix, and the column of another matrix in a single MPI_SEND, how can I do this procedure?
MPI_SEND (row and column of the matrix ...)
Since C/C++ works in row major order, you can either declare your 2D matrix in a 1D vector and access its entries by using a simple convention. Assuming A is of size mxn and B is a vector;
A[i][j] = B[i*n+j];
But if you are coding in C++, I would suggest defining a matrix object and try sending these objects in MPI. You would have to create your own MPI_Data_Type.
Related
I have observations in vector form and I want to calculate the covariance matrix and the mean from these observations in OpenCV using calcCovarMatrix:
http://docs.opencv.org/modules/core/doc/operations_on_arrays.html
My current function call is:
calcCovarMatrix(descriptors.at(j).descriptor.t(), covar, mean, CV_COVAR_ROWS);
Whereas descriptors.at(j).descriptor.t() is one matrix with 2 columns and 390 rows. So my "random variables" are the rows of this matrix. The covar and mean are empty matrices.
The function calculates covar correctly and retuns a 390x390 matrix. But the mean is just a matrix with 1 row and 2 columns. I do not get this. I am expecting a matrix with 1 columnd and 390 rows (a column vector).
Am I using the wrong variant of the function? If yes, how should I use the correct variant in my case, I am specifically pointing to the value for the nsamples parameter. I don't know two what value to set it.
I created a m-by-n matrix Mat and I would like to add a scalar to just one row of this matrix. In order to add a scalar to all elements of the matrix, you can use the following statement: A += b, where A is a Mat object and b in a scalar. But if I wanted to add a scalar to just one row of this matrix, how to perform this operation just as easily?
This is very easy:
image.row(i) += Scalar(...);
Taken from docs:
There are many different ways to create a Mat object. The most popular
options are listed below:
...
Construct a header for a part of another
array. It can be a single row, single column, several rows, several
columns, rectangular region in the array (called a minor in algebra)
or a diagonal. Such operations are also O(1) because the new header
references the same data. You can actually modify a part of the array
using this feature
...
A common thing to do in machine learning is to have the first column of a dataset represent the class that the corresponding row belongs to for a data point.
Basically, I have a cv::Mat and I want to efficiently create a cv::Mat containing that matrix with the first column removed. Is there a more efficient way of doing this than looping over the columns and rows and adding the elements one by one with mat.at<data_type>(row, col) = elem; ?
See Mat::operator() from OpenCV documentation.
I want to transform this data (I was told to do it from the object perspective). A list of the data is:
[0, -20.790001, -4.49] make up the acceleration xyz coordinates - accel(x,y,z).
[-0.762739, -3.364226, -8.962189] make up angle xyz coordinates - angle(x,y,z).
I am trying to use Rodrigues’ rotation formula or linear transformation matrix for rotation? Is this different with sensor data?
I am able to read the data from .csv, but am unsure how to transform into C++ and how to create a matrix in C++.
As long as you have a formula for transformation of the data, you just need to apply it. As for the matrix and creating one, there are multiple ways, either by using a double array:
float matrix[][] ( or matrix** if you want to use pointers )
or using a class (or struct, up to you) which contains the rows and columns
class Matrix
float rows[]
float columns[]
Good luck!
Note: just pseudo code definitely won't work out of the box, obviously
How can I access a single vector from a matrix?
For example: Is there a way to extract a vector using something like A(i) for a matrix Eigen::MatrixXf A(10,10) that returns an Eigen::VectorXf A(10)?
Found in the documentation :/
The way to access a single column is .col(i), and similarly for row, its .row(i). Also of interest is .block<>.