我正在尝试尽快计算许多 3x1 向量对的叉积。这
\n\n\n\nn = 10000\na = np.random.rand(n, 3)\nb = np.random.rand(n, 3)\nnumpy.cross(a, b)\nRun Code Online (Sandbox Code Playgroud)\n\n给出了正确的答案,但受到类似问题的答案的启发,我认为这einsum会让我有所收获。我发现两者
eijk = np.zeros((3, 3, 3))\neijk[0, 1, 2] = eijk[1, 2, 0] = eijk[2, 0, 1] = 1\neijk[0, 2, 1] = eijk[2, 1, 0] = eijk[1, 0, 2] = -1\n\nnp.einsum(\'ijk,aj,ak->ai\', eijk, a, b)\nnp.einsum(\'iak,ak->ai\', np.einsum(\'ijk,aj->iak\', eijk, a), b)\nRun Code Online (Sandbox Code Playgroud)\n\n计算叉积,但它们的性能令人失望:两种方法的性能都比np.cross:
%timeit np.cross(a, b)\n1000 loops, best of 3: 628 \xc2\xb5s per loop\nRun Code Online (Sandbox Code Playgroud)\n\n\n\n%timeit np.einsum(\'ijk,aj,ak->ai\', eijk, a, b)\n100 loops, …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用R来执行操作(理想情况下具有类似显示的输出),例如
> x<-1:6
> y<-1:6
> x%o%y
[,1] [,2] [,3] [,4] [,5] [,6]
[1,] 1 2 3 4 5 6
[2,] 2 4 6 8 10 12
[3,] 3 6 9 12 15 18
[4,] 4 8 12 16 20 24
[5,] 5 10 15 20 25 30
[6,] 6 12 18 24 30 36
Run Code Online (Sandbox Code Playgroud)
通过添加而不是乘法找到每个条目.
我也有兴趣创建36个有序对(1,1),(1,2)等...
此外,我想使用另一个矢量
z<-1:4
Run Code Online (Sandbox Code Playgroud)
在x,y和z之间创建所有可能的有序三元组.
我正在使用R来研究滚动骰子时可能总数的可能性.
谢谢你的帮助!这个网站对我有很大的帮助.我感谢任何花时间回答陌生人问题的人.
更新所以我发现`outer(x,y,'+')将首先做我想要的.但我仍然不知道如何创建有序对或有序三元组.
我有两个清单:
List<Integer> list1 = ...
List<Integer> list2 = ...
Run Code Online (Sandbox Code Playgroud)
我有以下课程:
class Pair {
public Pair(final Integer i1, final Integer i2) {
...
}
}
Run Code Online (Sandbox Code Playgroud)
Java8流是否可以将两个输入列表组合成List<Pair>?这可以通过双循环来轻松完成,但我想知道Java8流是否可行.
我正在尝试使用Linq执行微积分交叉产品计算并尝试找出以下代码的模式:
static void Main(string[] args)
{
double[] a = { 1, -1, -1 };
double[] b = {.5,1,.5};
var cross = from x in a
from y in b
select new {x,y};
List<double> LeftSide = new List<double>();
foreach (var c in cross) {
Console.WriteLine("x = " + c.x + " y = " + c.y);
double res = c.x * c.y;
Console.WriteLine("");
LeftSide.Add(res);
}
double i = LeftSide[5] - LeftSide[7];
double j = LeftSide[2] - LeftSide[6];
double k = LeftSide[1] …Run Code Online (Sandbox Code Playgroud) 我正在尝试在R中创建一个独特用户的跨产品矩阵.我在SO上搜索它但找不到我想要的东西.任何帮助表示赞赏.我有一个大型数据框(超过一百万),并显示了一个示例:
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'))
Run Code Online (Sandbox Code Playgroud)
df的输出是:
Products Users
1 Product a user1
2 Product b user1
3 Product a user2
4 Product c user1
5 Product b user2
6 Product c user3
Run Code Online (Sandbox Code Playgroud)
我想看到两个矩阵:第一个将显示具有任一产品(OR)的唯一用户的数量 - 因此输出将类似于:
Product a Product b Product c
Product a 2 3
Product b 2 3
Product c 3 3
Run Code Online (Sandbox Code Playgroud)
第二个矩阵将是具有两个产品(AND)的唯一用户数:
Product a Product b Product c
Product a 2 1
Product …Run Code Online (Sandbox Code Playgroud) 我有两个表,我想加入,但我收到MySQL的错误
Table: books
bookTagNum ShelfTagNum
book1 1
book2 2
book3 2
Table: shelf
shelfNum shelfTagNum
1 shelf1
2 shelf2
Run Code Online (Sandbox Code Playgroud)
我希望我的结果是:
bookTagNum ShelfTagNum shelfNum
book1 shelf1 1
book2 shelf2 2
book3 shelf2 2
Run Code Online (Sandbox Code Playgroud)
但相反,我也得到了额外的结果:
book1 shelf2 2
Run Code Online (Sandbox Code Playgroud)
我认为我的查询是在进行交叉产品而不是连接:
SELECT `books`.`bookTagNum` , `books`.`shelfNum` , `shelf`.`shelfTagNum` , `books`.`title`
FROM books, shelf
where `books`.`shelfNum`=`books`.`shelfNum`
ORDER BY `shelf`.`shelfTagNum` ASC
LIMIT 0 , 30
Run Code Online (Sandbox Code Playgroud)
我究竟做错了什么?
我需要计算一个帽子矩阵(如线性回归)。标准 R 代码将是:
H <- tcrossprod(tcrossprod(X, solve(crossprod(X))), X)
用X是相对大的矩阵(即1E5 * 100),并且该线具有运行数千次。我知道最大的限制部分是逆计算,但叉积也可能很耗时。有没有更快的替代方法来执行这些矩阵运算?我尝试了 Rcpp 并查看了几篇文章,但我测试的任何替代方法都较慢。也许我没有正确编写 C++ 代码,因为我不是高级 C++ 程序员。
谢谢!
作为我正在编写的程序的一部分,我需要找到双向量和复数双向量的交叉乘积.我写了一个我认为应该这样做的函数,但是当我调用它时,我收到以下错误:
error: no matching function for call to ‘CrossProduct1D(std::vector< double, std::allocator<double> >&, std::vector<std::complex<double>, std::allocator<std::complex<double> > >&)’
Run Code Online (Sandbox Code Playgroud)
这是我的代码:
#include <iostream>
#include <fstream>
#include <sstream>
#include <string>
#include <vector>
#include <math.h>
#include <complex>
using namespace std;
//1D cross product
template <typename T>
vector<T> CrossProduct1D(vector<T> const &a, vector<T> const &b)
{
vector<T> r (a.size());
r[0] = a[1]*b[2]-a[2]*b[1];
r[1] = a[2]*b[0]-a[0]*b[2];
r[2] = a[0]*b[1]-a[1]*b[0];
return r;
}
//::::::::importing data from text::::::::::
vector<string> ezivec;
ezivec.reserve(4000);
string ezidat("ez.i.txt");
ifstream ezifile;
ezifile.open(ezidat.c_str());
if(!ezifile.is_open())
{
cerr<<"Error opening file …Run Code Online (Sandbox Code Playgroud) 我试图理解一个代码,其中作者将 3D 中的向量旋转了 90 度。他们使用了一个交叉产品来做到这一点。交叉乘积如何包含旋转 90 度?任何解释都会有所帮助。
% Inputs:
% V #vertices by dim list of mesh vertex positions
% F #faces by simplex-size list of mesh face indices
% Gradient of a scalar function defined on piecewise linear elements (mesh)
% is constant on each triangle i,j,k:
% grad(Xijk) = (Xj-Xi) * (Vi - Vk)^R90 / 2A + (Xk-Xi) * (Vj - Vi)^R90 / 2A
% grad(Xijk) = Xj * (Vi - Vk)^R90 / 2A + Xk * (Vj …Run Code Online (Sandbox Code Playgroud) matlab rotation linear-algebra cross-product geometry-surface
r ×3
performance ×2
c# ×1
c++ ×1
combinations ×1
function ×1
java ×1
java-8 ×1
java-stream ×1
linq ×1
matlab ×1
matrix ×1
numpy ×1
numpy-einsum ×1
python ×1
rcpp ×1
rotation ×1
sql ×1
unique ×1