matrix-multiplication

Matrix Multiplication giving wrong output [duplicate]

久未见 提交于 2020-01-25 07:13:04
问题 This question already has an answer here : Unable to execute device kernel in CUDA (1 answer) Closed 4 years ago . What I am attempting to do is Multiply Matrix A & Matrix B and then from the product matrix I get the index of the maximum value per column. But unfortunately, only the first 128*128 values of the matrix multiplication are correct while others are just garbage. I do not quite understand how this works. I request you to kindly guide me with this .. #include<stdio.h> #include "cuda

np.dot product between two 3D matrices along specified axis

强颜欢笑 提交于 2020-01-25 01:04:20
问题 I have two 3D matrices: a = np.random.normal(size=[3,2,5]) b = np.random.normal(size=[5,2,3]) I want the dot product of each slice along 2 and 0 axes respectively: c = np.zeros([3,3,5]) # c.size is 45 c[:,:,0] = a[:,:,0].dot(b[0,:,:]) c[:,:,1] = a[:,:,1].dot(b[1,:,:]) ... I would like to do that using np.tensordot (for efficiency and speed) I have tried: c = np.tensordot(a, b, axes=[2,0]) but I get a 4D array with 36 elements (instead of 45). c.shape, c.size = ((3L, 2L, 2L, 3L), 36). I have

numpy.array_equal returns False, even though arrays have the same shape and values

£可爱£侵袭症+ 提交于 2020-01-24 15:17:06
问题 I have a very simple function, as shown below def new_price(A, B, x): return np.linalg.inv(A @ B) @ x These are the inputs I give it A = np.array([ [2, 0, 1, 0], [1, 1, 1, 1], [0, 0, 0, 10] ]) B = np.array([ [3, 3, 3], [2, 0, 8], [0, 5, 3], [0, 0, 10] ]) x = np.array([ 84, 149, 500]) This returns the array [ 1. 3. 5.] . But, when I make the following equality check, it returns False v1 = new_price(A, B, x) v2 = np.array([1.0, 3.0, 5.0]) np.array_equal(new_price(A, B, [ 84, 149, 500]), np

numpy.array_equal returns False, even though arrays have the same shape and values

别等时光非礼了梦想. 提交于 2020-01-24 15:16:13
问题 I have a very simple function, as shown below def new_price(A, B, x): return np.linalg.inv(A @ B) @ x These are the inputs I give it A = np.array([ [2, 0, 1, 0], [1, 1, 1, 1], [0, 0, 0, 10] ]) B = np.array([ [3, 3, 3], [2, 0, 8], [0, 5, 3], [0, 0, 10] ]) x = np.array([ 84, 149, 500]) This returns the array [ 1. 3. 5.] . But, when I make the following equality check, it returns False v1 = new_price(A, B, x) v2 = np.array([1.0, 3.0, 5.0]) np.array_equal(new_price(A, B, [ 84, 149, 500]), np

MPI matrix-vector-multiplication returns sometimes correct sometimes weird values

谁都会走 提交于 2020-01-24 04:20:06
问题 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; vector = malloc(size*sizeof(double)); double *matrix = NULL; //Rank 0 ----------------------------------- if (rnk == 0) { //Initialize

How to update opengl modelview matrix with my own 4x4 matrix?

二次信任 提交于 2020-01-24 02:41:11
问题 I have 4x4 matrix for object's transformations. float mat44[16]; But i don't know how to update OpenGL ModelView matrix using my matrix. should i use glTranslatef()/glRotatef() with relavant values from my matrix or should i use glLoadMatrix(),glMultMatrix() ? Pls help. Thanks. 回答1: If you want to apply your transformation to current transformation already in OpenGL matrix stack, then you should write: glMultMatrixf(mat44); But if you want to discard what's currently on top of OpenGL matrix

Why does the Jama matrix inner dimension agree in the first iteration, but later it does not?

吃可爱长大的小学妹 提交于 2020-01-23 00:48:10
问题 Following Jama Matrices are defined in my code: P: 3*3 Matrix I: 3*3 identity Matrix K: 3*2 Matrix H: 2*3 Matrix Q: 3*3 Matrix Following is my code snippet: private Matrix getP() { P= (I.minus(K.times(H))).times(Q); Log.d("csv", "P is calculated"); return P; } While running the code, at first iteration it works, i.e, P is calculated is printed at the Logcat. However, it happens only once and the application gets stopped. Following is the error: java.lang.IllegalArgumentException: Matrix inner

Why does the Jama matrix inner dimension agree in the first iteration, but later it does not?

别说谁变了你拦得住时间么 提交于 2020-01-23 00:47:59
问题 Following Jama Matrices are defined in my code: P: 3*3 Matrix I: 3*3 identity Matrix K: 3*2 Matrix H: 2*3 Matrix Q: 3*3 Matrix Following is my code snippet: private Matrix getP() { P= (I.minus(K.times(H))).times(Q); Log.d("csv", "P is calculated"); return P; } While running the code, at first iteration it works, i.e, P is calculated is printed at the Logcat. However, it happens only once and the application gets stopped. Following is the error: java.lang.IllegalArgumentException: Matrix inner

LWJGL - Problems implementing 'roll' in a 6DOF Camera using quaternions and a translation matrix

狂风中的少年 提交于 2020-01-22 20:37:49
问题 I've spent a couple weeks on this issue and can't seem to find a proper solution and need some advice. I'm working on creating a Camera class using LWJGL/Java, and am using Quaternions to handle bearing (yaw), pitch and roll rotations. I'd like this camera to handle all 6 degrees of movement in 3D space, and roll. Bearing, Pitch and Roll are all quaternions. I multiply them into a 'change' quaternion, and create a translation matrix from that. I put that in a float buffer, and multiply the

Multiply two 100-Digit Numbers inside Excel Using Matrix

匆匆过客 提交于 2020-01-20 09:40:32
问题 I want to multiply two 100-Digit Numbers In Excel using matrix. The issue in Excel is that after 15-digit, it shows only 0. So, the output also need to be in a Matrix. 1st Number: "9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999" 2nd Number: "2222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222" Output: