matrix

How to iterate through a cvMat matrix in JavaCV?

与世无争的帅哥 提交于 2020-01-01 12:16:12
问题 I have an IplImage that I converted in a Matrix, and now I want to iterate cell by cell. CvMat mtx = new CvMat(iplUltima); for (int i = 0; i < 100; i++) { //I need something like mtx[0][i] = someValue; } 回答1: ¡¡I DID IT!! I share it: CvMat mtx = new CvMat(iplUltima); for (int i = 0; i < 100; i++) { for (int j = 0; j < 100; j++) { opencv_core.cvSet2D(mtx, i, j, CvScalar.ONE); } } iplUltima = new IplImage (mtx); Where i = row and j = column 回答2: First, you need to import the following from

Smooth animation using MatrixTransform?

橙三吉。 提交于 2020-01-01 12:14:06
问题 I'm trying to do an Matrix animation where I both scale and transpose a canvas at the same time. The only approach I found was using a MatrixTransform and MatrixAnimationUsingKeyFrames. Since there doesnt seem to be any interpolation for matrices built in (only for path/rotate) it seems the only choice is to try and build the interpolation and DiscreteMatrixKeyFrame's yourself. I did a basic implementation of this but it isnt exactly smooth and I'm not sure if this is the best way and how to

Spiral loop on a matrix from a point

我的梦境 提交于 2020-01-01 10:46:48
问题 I have a 2D grid as follow and want to start from X, Y and save the corner of a window (W) and overlap of (OP). I have tried these codes, but non of them are fit to my purpose. As it is demonstrated, I want to start from a random point (black cell) and save the corner locations (shown by black circles) of each new window in a spiral loop. The algorithm should be used for any grid sizes (not square necessarily) and any start point locations. Matlab also has a function (spiral) that is similar

CSR Matrix - Matrix multiplication

我是研究僧i 提交于 2020-01-01 10:38:50
问题 I have two square matrices A and B I must convert B to CSR Format and determine the product C A * B_csr = C I have found a lot of information online regarding CSR Matrix - Vector multiplication. The algorithm is: for (k = 0; k < N; k = k + 1) result[i] = 0; for (i = 0; i < N; i = i + 1) { for (k = RowPtr[i]; k < RowPtr[i+1]; k = k + 1) { result[i] = result[i] + Val[k]*d[Col[k]]; } } However, I require Matrix - Matrix multiplication. Further, it seems that most algorithms apply A_csr - vector

Python Numpy vectorize nested for-loops for combinatorics

笑着哭i 提交于 2020-01-01 10:07:26
问题 Given an nxn array A of real positive numbers, I'm trying to find the minimum of the maximum of the element-wise minimum of all combinations of three rows of the 2-d array. Using for-loops, that comes out to something like this: import numpy as np n = 100 np.random.seed(2) A = np.random.rand(n,n) global_best = np.inf for i in range(n-2): for j in range(i+1, n-1): for k in range(j+1, n): # find the maximum of the element-wise minimum of the three vectors local_best = np.amax(np.array([A[i,:],

Solving a system of linear equations in a non-square matrix [closed]

微笑、不失礼 提交于 2020-01-01 09:54:11
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 5 months ago . I have a system of linear equations that make up an NxM matrix (i.e. Non-square) which I need to solve - or at least attempt to solve in order to show that there is no solution to the system. (more likely than not, there will be no solution) As I understand it, if my matrix is not square (over or under

Getting elements of a matrix with vectors of coordinates

牧云@^-^@ 提交于 2020-01-01 09:53:06
问题 This is a really basic question, but I can't seem to solve it or find an answer for it anywhere : suppose I have two vectors x,y of coordinates and a matrix m . I would like a vector z such that z[i] = m[x[i],y[i]] for all i . I tried z=m[x,y] , but that creates a memory overflow. The vector and matrix are quite large so looping is pretty much out of the question. Any ideas ? 回答1: Use cbind . Here's a simple example: mat <- matrix(1:25, ncol = 5) mat # [,1] [,2] [,3] [,4] [,5] # [1,] 1 6 11

Function which returns the least-squares solution to a linear matrix equation

浪尽此生 提交于 2020-01-01 09:18:16
问题 I have been trying to rewrite the code from Python to Swift but I'm stuck on the function which should return the least-squares solution to a linear matrix equation. Does anyone know a library written in Swift which has an equivalent method to the numpy.linalg.lstsq ? I'd be grateful for your help. Python code: a = numpy.array([[p2.x-p1.x,p2.y-p1.y],[p4.x-p3.x,p4.y-p3.y],[p4.x-p2.x,p4.y-p2.y],[p3.x-p1.x,p3.y-p1.y]]) b = numpy.array([number1,number2,number3,number4]) res = numpy.linalg.lstsq(a

Function which returns the least-squares solution to a linear matrix equation

只愿长相守 提交于 2020-01-01 09:18:10
问题 I have been trying to rewrite the code from Python to Swift but I'm stuck on the function which should return the least-squares solution to a linear matrix equation. Does anyone know a library written in Swift which has an equivalent method to the numpy.linalg.lstsq ? I'd be grateful for your help. Python code: a = numpy.array([[p2.x-p1.x,p2.y-p1.y],[p4.x-p3.x,p4.y-p3.y],[p4.x-p2.x,p4.y-p2.y],[p3.x-p1.x,p3.y-p1.y]]) b = numpy.array([number1,number2,number3,number4]) res = numpy.linalg.lstsq(a

Optimising and why openmp is much slower than sequential way?

試著忘記壹切 提交于 2020-01-01 08:54:15
问题 I am a newbie in programming with OpenMp. I wrote a simple c program to multiply matrix with a vector. Unfortunately, by comparing executing time I found that the OpenMP is much slower than the Sequential way. Here is my code (Here the matrix is N*N int, vector is N int, result is N long long): #pragma omp parallel for private(i,j) shared(matrix,vector,result,m_size) for(i=0;i<m_size;i++) { for(j=0;j<m_size;j++) { result[i]+=matrix[i][j]*vector[j]; } } And this is the code for sequential way: