cross-product

Cross product of vectors in C++

流过昼夜 提交于 2019-12-13 03:36:39
问题 As a part of a program that I'm writing, I need to find the cross product of a vector of doubles and a vector of complex doubles. I've written a function that I feel should do this, but when I call it, I get the following error: error: no matching function for call to ‘CrossProduct1D(std::vector< double, std::allocator<double> >&, std::vector<std::complex<double>, std::allocator<std::complex<double> > >&)’ Here is my code: #include <iostream> #include <fstream> #include <sstream> #include

cross products with einsums

喜欢而已 提交于 2019-12-11 06:54:17
问题 I'm trying to compute the cross-products of many 3x1 vector pairs as fast as possible. This n = 10000 a = np.random.rand(n, 3) b = np.random.rand(n, 3) numpy.cross(a, b) gives the correct answer, but motivated by this answer to a similar question, I thought that einsum would get me somewhere. I found that both eijk = np.zeros((3, 3, 3)) eijk[0, 1, 2] = eijk[1, 2, 0] = eijk[2, 0, 1] = 1 eijk[0, 2, 1] = eijk[2, 1, 0] = eijk[1, 0, 2] = -1 np.einsum('ijk,aj,ak->ai', eijk, a, b) np.einsum('iak,ak-

Generate matrix of unique user-item cross-product combinations

﹥>﹥吖頭↗ 提交于 2019-12-10 11:30:18
问题 I am trying to create a cross-product matrix of unique users in R. I searched for it on SO but could not find what I was looking for. Any help is appreciated. I have a large dataframe (over a million) and a sample is shown: df <- data.frame(Products=c('Product a', 'Product b', 'Product a', 'Product c', 'Product b', 'Product c'), Users=c('user1', 'user1', 'user2', 'user1', 'user2','user3')) Output of df is: Products Users 1 Product a user1 2 Product b user1 3 Product a user2 4 Product c user1

R - Compute Cross Product of Vectors (Physics)

ⅰ亾dé卋堺 提交于 2019-12-06 04:28:28
问题 What am I doing wrong? > crossprod(1:3,4:6) [,1] [1,] 32 According to this website:http://onlinemschool.com/math/assistance/vector/multiply1/ It should give: {-3; 6; -3} See also What is R's crossproduct function? 回答1: Here is a generalized cross product: xprod <- function(...) { args <- list(...) # Check for valid arguments if (length(args) == 0) { stop("No data supplied") } len <- unique(sapply(args, FUN=length)) if (length(len) > 1) { stop("All vectors must be the same length") } if (len !

Does the method for computing the cross-product change for left handed coordinates?

放肆的年华 提交于 2019-12-05 02:46:58
Does the method for computing the cross-product change for left handed coordinates? Sven Marnach The formula for the cross product of the vectors (x1, x2, x3) and (y1, y2, y3) is z1 = x2 * y3 - x3 * y2 z2 = x3 * y1 - x1 * y3 z3 = x1 * y2 - x2 * y1 It is designed in a way that the three vectors x , y and z in the given order have the same handedness as the coordinate system itself. This property does not depend on the handedness of the coordinate system -- for a left-handed coordinate system the vectors fulfil the left-hand rule. You don't need to change anything about the formula. Useful links

R - Compute Cross Product of Vectors (Physics)

笑着哭i 提交于 2019-12-04 10:13:01
What am I doing wrong? > crossprod(1:3,4:6) [,1] [1,] 32 According to this website: http://onlinemschool.com/math/assistance/vector/multiply1/ It should give: {-3; 6; -3} See also What is R's crossproduct function? Here is a generalized cross product: xprod <- function(...) { args <- list(...) # Check for valid arguments if (length(args) == 0) { stop("No data supplied") } len <- unique(sapply(args, FUN=length)) if (length(len) > 1) { stop("All vectors must be the same length") } if (len != length(args) + 1) { stop("Must supply N-1 vectors of length N") } # Compute generalized cross product by

What should itertools.product() yield when supplied an empty list?

孤街醉人 提交于 2019-12-04 00:23:09
问题 I guess it's an academic question, but the second result does not make sense to me. Shouldn't it be as thoroughly empty as the first? What is the rationale for this behavior? from itertools import product one_empty = [ [1,2], [] ] all_empty = [] print [ t for t in product(*one_empty) ] # [] print [ t for t in product(*all_empty) ] # [()] Updates Thanks for all of the answers -- very informative. Wikipedia's discussion of the Nullary Cartesian Product provides a definitive statement: The

What should itertools.product() yield when supplied an empty list?

纵饮孤独 提交于 2019-12-01 03:43:14
I guess it's an academic question, but the second result does not make sense to me. Shouldn't it be as thoroughly empty as the first? What is the rationale for this behavior? from itertools import product one_empty = [ [1,2], [] ] all_empty = [] print [ t for t in product(*one_empty) ] # [] print [ t for t in product(*all_empty) ] # [()] Updates Thanks for all of the answers -- very informative. Wikipedia's discussion of the Nullary Cartesian Product provides a definitive statement: The Cartesian product of no sets ... is the singleton set containing the empty tuple. And here is some code you

In Perl, how can I get the Cartesian product of multiple sets?

心已入冬 提交于 2019-11-29 17:25:55
问题 I want to do permutation in Perl. For example I have three arrays: ["big", "tiny", "small"] and then I have ["red", "yellow", "green"] and also ["apple", "pear", "banana"] . How do I get: ["big", "red", "apple"] ["big", "red", "pear"] ..etc.. ["small", "green", "banana"] I understand this is called permutation. But I am not sure how to do it. Also I don't know how many arrays I can have. There may be three or four, so I don't want to do nested loop. 回答1: That's actually not permutation but

Calculate surface normals from depth image using neighboring pixels cross product

会有一股神秘感。 提交于 2019-11-28 17:35:19
As the title says I want to calculate the surface normals of a given depth image by using the cross product of neighboring pixels. I would like to use Opencv for that and avoid using PCL however, I do not really understand the procedure, since my knowledge is quite limited in the subject. Therefore, I would be grateful is someone could provide some hints. To mention here that I do not have any other information except the depth image and the corresponding rgb image, so no K camera matrix information. Thus, lets say that we have the following depth image: and I want to find the normal vector at