matrix

How do I remove an array dimension where the elements sum to zero?

I am assigning a 3D array, which contains some information for a number of different loadcases. Each row in the array defines a particular loadcase (of which there are 3) and I would like to remove the loadcase (i.e. the row) if ALL the elements of the row (in 3D) are equal to zero. The code I have at the moment is: Array = zeros(3,5) ...

Numpy ‘smart’ symmetric matrix

Is there a smart and space-efficient symmetric matrix in numpy which automatically (and transparently) fills the position at [j][i] when [i][j] is written to? a = numpy.symmetric((3, 3)) a[0][1] = 1 a[1][0] == a[0][1] # True print a # [[0 1 0], [1 0 0], [0 0 0]] assert numpy.all(a == a.T) # for any symmetric matrix An automatic Hermi...

Correlation Scatter-matrix plot with different point size (in R)

I just came a cross this nice code that makes this scatter matrix plot: And wanted to implement it to a likret scale variables (integers of 1 to 5) by making the dot's sizes/colors (in the lower triangle) differ according to how many options of that type occurs (like the effect the jitter might have given me). Any idea on how to do t...

Is there a better way to declare an empty, typed matrix in MATLAB?

Is there a way to "declare" a variable with a particular user-defined type in MATLAB? zeros() only works for built-in numeric types. The only solution I've come up with involves using repmat() to duplicate a dummy object zero times: arr = repmat(myClass(), [1 0]) Without declaring variables this way, any code which does "arr(end+1) = ...

Vector projection on matrix along diagonal.

Hello, Is there a easy way how to produce following matrix: a = 4 5 6 7 3 4 5 6 2 3 4 5 1 2 3 4 which is a projection of vector [1 2 3 4 5 6 7] along diagonal? thanks ...

wrong operator() overload called

okay, I am writing a matrix class and have overloaded the function call operator twice. The core of the matrix is a 2D double array. I am using the MinGW GCC compiler called from a windows console. the first overload is meant to return a double from the array (for viewing an element). the second overload is meant to return a reference ...

How to convert a grayscale matrix to an RGB matrix in MATLAB?

rgbImage = grayImage / max(max(grayImage)); or rgbImage = grayImage / 255; Which of the above is right,and reason? ...

How can I save and read from XML the new C++ style matrix objects in OpenCV?

The old, C style cvMat matrices could be passed to the cvSave() function for easy writing to an XML file. The new C++ style cv::Mat and cv::Mat_ matrices are not accepted by this function. The OpenCV reference has a section on XML persistence, but the three classes (FileStorage, FileNode and FileNodeIterator) lack any description or exam...

Efficient 4x4 matrix inverse (affine transform)

Hi, I was hoping someone can point out an efficient formula for 4x4 affine matrix transform. Currently my code uses cofactor expansion and it allocates a temporary array for each cofactor. It's easy to read, but it's slower than it should be. Note, this isn't homework and I know how to work it out manually using 4x4 co-factor expansio...

Is there a name for this type of algorithm?

I have a 2 dimensional array forming a table: [color][number][shape ] ------------------------- [black][10 ][square ] [black][10 ][circle ] [red ][05 ][triangle] [red ][04 ][triangle] [green][11 ][oval ] and what I want to do is group largest common denominators, such that we get: 3 groups group #1: color=bl...

Setting ModelView matrix using rotate, translate, etc.. vs setting manual matrix

When setting the ModelView matrix you normally go through several transformations from the identity matrix. for example: glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glRotatef(270.0f, 0.0f, 0.0f, 1.0f); glTranslatef(-rect.size.height / 2, -rect.size.width / 2, 0.0f); Instead of doing those operations one after the other (assume there...

What's a good matrix manipulation library available for C ?

Hi, I am doing a lot of image processing in C and I need a good, reasonably lightweight, and above all FAST matrix manipulation library with a permissive license. I am mostly focussing on affine transformations and matrix inversions, so i do not need anything too sophisticated or bloated. Primarily I would like something that is very f...

Logical Matrix .... Solution

Suppose you have an NxN matrix and you have to check whether it's a upper diagonal matrix or not. Is there any generic method to solve this problem? I am elaborating my question: Some thing is like this: Suppose you have NXN matrix having the value of N=4 then matrix will look like this: |5 6 9 2| |1 8 4 9| |5 8 1 6| |7 6 3 2| Its a ...

Two dimensional strings in C++

I want to write something like 2d strings in C++. I tried with : vector< vector<string> > table; int m,n,i,j; string s; cin>>n>>m; for(i=0;i<n;i++) { for(j=0;j<m;j++) { cin>>s; table[i][j] = s; } } cout << "\n...

Math: How to sum each row of a matrix

I have a 1x8 matrix of students where each student is a 4x1 matrix of scores. Something like: SCORES S [62, 91, 74, 14] T [59, 7 , 59, 21] U [44, 9 , 69, 6 ] D [4 , 32, 28, 53] E [78, 99, 53, 83] N [48, 86, 89, 60] T [56, 71, 15, 80] S [47, 67, 79, 40] Main question: Using sigma notation, or some other mathematical function, h...

The bigger value in a matrix row

How can I get the 2 biggers numbers of a matrix row? If the matrix have a bigger number in other row, it can't be shown. For example, let's suppose I have the following matrix int mat[][] ={{1,2,3}{4,5,6}{7,8,9}}; if I search the 2 biggers numbers from the row 0, it should return me the indexes 1 and 2 (values 2 and 3). ...

Get the indices of the n largest elements in a matrix

Suppose I have the following matrix: 01 02 03 06 03 05 07 02 13 10 11 12 32 01 08 03 And I want the indices of the top 5 elements (in this case, 32, 13, 12, 11, 10). What is the cleanest way to do this in MATLAB? ...

Make c# matrix code faster

Hi all, Working on some matrix code, I'm concerned of performance issues. here's how it works : I've a IMatrix abstract class (with all matrices operations etc), implemented by a ColumnMatrix class. abstract class IMatrix { public int Rows {get;set;} public int Columns {get;set;} public abstract float At(int row, int colum...

Can anyone recommend some Transformation Matrix tutorials for dummies?

Can anyone recommend some good starting points for understanding Transformation Matrices for dummies like me with poor math skills. I'm willing to learn the math, and I'm not a complete idiot (I hope) but the examples I'm finding seem to require a huge leap from what I know, to what I need to know. ...

How do I go about overloading C++ operators to allow for chaining?

I, like so many programmers before me, am tearing my hair out writing the right-of-passage-matrix-class-in-C++. I have never done very serious operator overloading and this is causing issues. Essentially, by stepping through This is what I call to cause the problems. cMatrix Kev = CT::cMatrix::GetUnitMatrix(4, true); Kev *= 4.0...