matrix

Map upper triangular matrix on vector skipping the diagonal

帅比萌擦擦* 提交于 2020-01-03 17:29:58
问题 I have a problem that could be boiled down to finding a way of mapping a triangular matrix to a vector skipping the diagonal. Basically I need to translate this C++ code using the Gecode libraries // implied constraints for (int k=0, i=0; i<n-1; i++) for (int j=i+1; j<n; j++, k++) rel(*this, d[k], IRT_GQ, (j-i)*(j-i+1)/2); Into this MiniZinc (functional) code constraint forall ( i in 1..m-1 , j in i+1..m ) ( (differences[?]) >= (floor(int2float(( j-i )*( j-i+1 )) / int2float(2)) )); And I

Image rotation(by 90 degress) in OpenCV

情到浓时终转凉″ 提交于 2020-01-03 17:23:47
问题 Can anyone suggest me how to rotate an image by 90 degrees? any implemented function in opencv? i think transpose of an image is totally different from 90 degree rotation (both clockwise and anti-clockwise) 回答1: It's not the most efficient way, but it's so easy cv::transpose(img, res); cv::flip(res, res, 1); 来源: https://stackoverflow.com/questions/20696765/image-rotationby-90-degress-in-opencv

How to ensure Eigen isometry stays isometric?

冷暖自知 提交于 2020-01-03 16:58:59
问题 I am currently looking into Eigen::Isometry3f , defined as typedef Transform<float,3,Isometry> Isometry3f; . Therewith i cannot, for example, assign an Affine3f to that Isometry3f , which is good to keep the isometry intact. (The reason is, that Mode is checked in the assignment operator of Transform .) I can however - via the Transform::operator(...) , which shortcuts to Transform::m_matrix(...) - do Eigen::Isometry3f iso; iso.setIdentity(); iso(1, 1) = 2; //works (but should not ?!) and

Lift value calculation

假装没事ソ 提交于 2020-01-03 14:00:40
问题 I have a (symmetric) adjacency matrix, which has been created based on the co-occurence of names (e.g.: Greg, Mary, Sam, Tom) in newspaper articles (e.g.: a,b,c,d). See below. How to calculate the lift value for the non-zero matrix elements (http://en.wikipedia.org/wiki/Lift_(data_mining))? I would be interested in an efficient implementation, which could also be used for very large matrices (e.g. a million non-zero elements). I appreciate any help. # Load package library(Matrix) # Data A <-

Lift value calculation

拈花ヽ惹草 提交于 2020-01-03 14:00:29
问题 I have a (symmetric) adjacency matrix, which has been created based on the co-occurence of names (e.g.: Greg, Mary, Sam, Tom) in newspaper articles (e.g.: a,b,c,d). See below. How to calculate the lift value for the non-zero matrix elements (http://en.wikipedia.org/wiki/Lift_(data_mining))? I would be interested in an efficient implementation, which could also be used for very large matrices (e.g. a million non-zero elements). I appreciate any help. # Load package library(Matrix) # Data A <-

How to compute cosine similarity using two matrices

跟風遠走 提交于 2020-01-03 11:40:12
问题 I have two matrices, A (dimensions M x N) and B (N x P). In fact, they are collections of vectors - row vectors in A, column vectors in B. I want to get cosine similarity scores for every pair a and b , where a is a vector (row) from matrix A and b is a vector (column) from matrix B. I have started by multiplying the matrices, which results in matrix C (dimensions M x P). C = A*B However, to obtain cosine similarity scores, I need to divide each value C(i,j) by the norm of the two

How do you edit cells in a sparse matrix using scipy?

谁说胖子不能爱 提交于 2020-01-03 09:58:28
问题 I'm trying to manipulate some data in a sparse matrix. Once I've created one, how do I add / alter / update values in it? This seems very basic, but I can't find it in the documentation for the sparse matrix classes, or on the web. I think I'm missing something crucial. This is my failed attempt to do so the same way I would a normal array. >>> from scipy.sparse import bsr_matrix >>> A = bsr_matrix((10,10)) >>> A[5][7] = 6 Traceback (most recent call last): File "<pyshell#11>", line 1, in

Given a list of numbers, find all matrices such that each column and row sum up to 264

不打扰是莪最后的温柔 提交于 2020-01-03 08:42:17
问题 Let's say I have a list of 16 numbers. With these 16 numbers I can create different 4x4 matrices. I'd like to find all 4x4 matrices where each element in the list is used once, and where the sum of each row and each colum is equal to 264. First I find all combination of elements within the list that sum up to 264 numbers = [11, 16, 18, 19, 61, 66, 68, 69, 81, 86, 88, 89, 91, 96, 98, 99] candidates = [] result = [x for x in itertools.combinations(numbers, 4) if sum(x) == 264] result becomes a

How to calculate the shift parameters of glTranslatef function in opengl

 ̄綄美尐妖づ 提交于 2020-01-03 05:31:35
问题 I am a newbie to opengl and confused about how to caculate the parameters of glTranslatef. Here is my display code void display() { glPushMatrix(); glClearColor(1.0f, 1.0f, 1.0f, 1.0f); // background glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT); glScalef(1.f,1.f,1.f); glTranslatef(2.f,0.f,0); glBegin(GL_QUADS); glVertex2f(-1.0f,-1.0f); glTexCoord2f(0.0f,1.0f); glVertex2f(1.0f,-1.0f); glTexCoord2f(0.0f,0.0f); glVertex2f(1.0f,1.0f); glTexCoord2f(1.0f,0.0f); glVertex2f(-1.0f,1.0f);

Building a hollow cube and filing it with small cubes in MATLAB

末鹿安然 提交于 2020-01-03 05:17:23
问题 I want to build a hollow cube with some dimensions x, y, and z, and fill its volume with many small cubes. The following image is similar to what I want to do, But, instead of small spheres, I want to use small cubes. After building the cube and filling it with other small cubes, I want to build a matrix that represents these small cubes inside the big one, this is because I want to be able to access every small cube, where I need to change its color . Is it possible to have this matrix