I'm working on a threaded implementation of matrix multiplication to work with my custom Matrix class, and I'm running into some issues with speed-up. Setting up and calling the operation looks like this: Matrix<double> left(2,2); left[0][0] = 1; left[0][1] = 2; left[1][0] = 3; left[1][1] = 4; Matrix<double> right(2,2); right[0][0]...

Let matrices a, b be [ 1, 2, 3, 4 ] i.e of (1 x 4) dimension. On applying numpy.dot(a, b) the result is 30 instead of raising exception that both the matrices shapes are not aligned. How can a (m x n) matrix be multiplied with (m x n)...

a = 1 2 3 b = 1 2 3 a.*b ans = 1 2 3 2 4 6 3 6 9 I used the .* operator to multiply a row vector and a column vector in Octave to see the results. I dont understand how the answer is obtained....

I've a two matrices A = [0 0 0; 0 0 0; 0 0 0] and B = [2 3 4;] How will I get A = [0 0 0; 2 3 4; 0 0 0]...

I have implemented a script that does constrained optimization for solving the optimal parameters of Support Vector Machines model. I noticed that my script for some reason gives inaccurate results (although very close to the real value). For example the typical situation is that the result of a calculation should...

Let m, n be integers such that 0<= m,n< N. Define: Algorithm A: Computes m + n in time O(A(N)) Algorithm B: Computes m*n in time O(B(N)) Algorithm C: Computes m mod n in time O(C(N)) Using any combination of algorithms A, B and C describe an algorithm for N...

The given task is to call a function from within another function, where both functions are handling matrices. Now lets call this function 1 which is in its own file: A = (1/dot(v,v))*(Ps'*Ps); Function 1 is called with the command: bpt = matok(P); Now in another file in the same...

If I have a numpy.ndarray A and a scipy.sparse.csc_matrix B, how do I take A dot B? I can do B dot A by saying B.dot(A), but the other way I can only think of this: B.T.dot(A.T).T Is there a more direct method to do this? ...

I'm attempting to add a small value to a World Matrix in order to replicate the accuracy of a fired weapon [pistol, assault rifle] Currently, my World Matrix resides at a Parent Objects' position, with the ability to rotate about the Y axis exclusively. I've done this in Unity3D, running...

I am trying to do an element-wise multiplication for two large sparse matrices. Both are of size around (400K X 500K), with around 100M elements. However, they might not have non-zero elements in the same positions, and they might not have the same number of non-zero elements. In either situation,...

I'm currently developing a CrossPlatform Graphic Engine, and the performance analysis says that I should optimize the matrixmultiplication. Y check the matrices for modifications so I don't update the matrices if there is no change, but anyway, the world matrix multiplications are using a lot of processing percent. Is there...

I have the following code: //Start MPI... MPI_Init(&argc, &argv); int size = atoi(argv[1]); int delta = 10; int rnk; int p; int root = 0; MPI_Status mystatus; MPI_Comm_rank(MPI_COMM_WORLD, &rnk); MPI_Comm_size(MPI_COMM_WORLD, &p); //Checking compatibility of size and number of processors assert(size % p == 0); //Initialize vector... double *vector = NULL;...

EDITED (the example contained mistake so I replaced it with another one) The following code is just an example how does it work: CATransform3D temp = CATransform3DIdentity; temp.m34 = -0.002; temp = CATransform3DTranslate(temp, 0, -230, 0); temp = CATransform3DRotate(temp, -M_PI / 5, 1, 0, 0); temp = CATransform3DTranslate(temp, 0, 230,...

this here is an attempt to a Hill Cipher, so far so good until multiplication of the 2nd and 3rd trigram. I really don't understand where my mistake is. Basicly what I have to do is a list multiplication. with this code I create a list of list key=[k[x:x+3] for...

This question already has an answer here: Create a matrix with A(i, j) = i*j 3 answers I want to declare a function that takes (n, m) as inputs an return mt as a n-by-m matrix. and if I assume that the row number (rn) and the column number...

During my acquaintance with CUDA in Python (numba lib), I implemented matrix provide methods: Just with numpy.dot() Strassen algorithm with numpy.dot() Blocks method on GPU Strassen algorithm on GPU So I tested it on 2 types of data: numpy.random.randint(0, 5, (N, N)) # with int32 elements numpy.random.random((N, N)) # with...

I have matrix A and matrices [U,S,V], such that [U, S, V] = svd(A). How could I amend my script in matlab to get the 10 columns of U that correspond to the 10 largest singular values of A (i.e. the largest values in S)? Thanks...

I'm trying to multiple two matrices, A and B, where B has more columns than A using python and numpy preferably. Example: A = numpy.matrix([[2,3,15],[5,8,12],[1,13,4]], dtype=numpy.object) B = numpy.matrix([[2,15,6,15,8,14],[17,19,17,7,18,14],[24,14,0,24,2,11]], dtype=numpy.object) ( A*B ) = [[415,297,63,411,100,235],[434,395,166,419,208,314], [319,318,227,202,250,240]] I've found some examples if they are arrays but none if they are matrices....

I have two arrays to compare. Label True/False from a comparing b : a=c(2.9,3.7,3.8, 2.7,3.3, 3.9) and b=c(18,21, 30 ,21, 17, 27) And I use compare=outer(a,a,'>=') & outer(b,b,'>=') # Return True if a[1]>=a[2] and b[1]>=b[2], etc to get a boolean matrix: [,1] [,2] [,3] [,4] [,5] [,6] [1,] TRUE FALSE...

I am wondering is there a way of calculating matrix multiplication using NumericMatrix and NumericVector class. I am wondering if there is any simple way to help me avoid the following loop to conduct this calculation. I just want to calculate X%*%beta. // assume X and beta are initialized and...

An algorithm I'm working on requires computing, in a couple places, a type of matrix triple product. The operation takes three square matrices with identical dimensions, and produces a 3-index tensor. Labeling the operands A, B and C, the (i,j,k)-th element of the result is X[i,j,k] = \sum_a A[i,a] B[a,j]...

We've got a columnvector m x 1 and a matrix m x n. For the value in row i in the columnvector we want to multiply this value with each value in the same row i of the matrix, and then sum all of these up. This is to be...

I'm learning three.js and am trying to multiply two translation matrices together to get a single matrix that describes both translations: | 1 0 0 -2 | | 1 0 0 3 | | 0 1 0 7 | * | 0 1 0 4 | | 0 0 1...

I have a large data matrix and I want calculate the similarity matrix of that large matrix but due to memory limitation I want to split the calculation. Lets assume I have following: For the example I have taken a smaller matrix data1 = data/np.linalg.norm(data,axis=1)[:,None] (Pdb) data1 array([[ 0. ,...

I have written this program and I am having some trouble understanding how to use multiple blocks by using dim3 variable in the kernel call line. This code works fine when I am doing 1000*1000 matrix multiplication, but not getting correct answer for lower dimensions like 100*100 , 200*200. #include...

I have a matrix, say, P of size (X,Y). Also, I have two matrices, say, Kx and Ky of size (M,N) both, a matrix pk of size (M,N) and two vectors u and v of X and Y respectively. For example, they can be defined as follows: import numpy as...

I'm doing some large stochastic matrices (at least 1000x1000) calculation in C++, using the Eigen Library, my code consists of the following functions : Eigen::VectorXd grid(...); initializes (element by element) a sorted vector of log-normally distributed values, using the quicksort algorithm and the ran1 algorithm, let's say of size N,...

I'm not really sure how to word this correctly but I would like to count the number of times there are similarities among the columns. Imagine I have the 3 NFL teams listed below. Zeroes are losses and ones are victories. The rows are the week of the NFL season....

By matrix multiplication I get the following matrix, which, let's say, shows how many customers who purchased product A, sooner or later, also purchased product B, product C and so on. Obviously, the diagonal values represent 100% of all purchases of a particular product. I'm looking for a way of...

In MATLAB I want to multiply an Nx4 matrix by a 4xN matrix and get an Nx1 vector out of it. I'm also dividing the result element-wise by another vector. In a loop, it would be: A=rand(10,4); B=rand(4,10); L=rand(10,1); for i=1:10 result(i)=A(i,:)*B(:,i)/L(i); end The only non-loop method I can think...

In the case of multiple of same matrix matA, like matA.transpose()*matA, You dont have to compute all result product, becouse the result matrix is symmetric(so only if the m>n), in my specific case is always symmetric! square. So ith enough the compute only for. ex. lower trinagular part and rest...

I am trying to speed up matrix multiplication on multicore architecture. For this end, I try to use threads and SIMD at the same time. But my results are not good. I test speed up over sequential matrix multiplication: void sequentialMatMul(void* params) { cout << "SequentialMatMul started."; int i, j,...

I'm building a suite of functions to work with a multidimensional-array data structure and I want to be able to define arbitrary slices of the arrays so I can implement a generalized inner product of two arbitrary matrices (aka Tensors or n-d arrays). An APL paper I read (I honestly...

I wanted to make matrix of points and rotate them for a custom angle. I get a bunch of 0's when I enter the desired angle, can't figure out why. Might be a pretty simple mistake, I'm kind of new to programming in C, trying to learn. Here's my code:...

Currently, I made a neural networks program in the cuda c. Because I needed to manipulate the matrix multiplication, I did not use CUBLAS for MM. I use the following code for MM. I was wondering if any one has some advice to make it faster which can be very...