gpt4 book ai didi

How to calculate the Cartesian product of two vectors?(如何计算两个向量的笛卡尔乘积?)

转载 作者:bug小助手 更新时间:2023-10-24 17:10:57 32 4
gpt4 key购买 nike



Is there an efficient method to calculate the Cartesian product of two vectors in DolphinDB?

在DolphinDB中有没有一种有效的方法来计算两个矢量的笛卡尔乘积?


For example, given the vectors ['aa', 'bb'] and ['cc', 'dd'], the desired result is ['aacc', 'aadd', 'bbcc', 'bbdd'] without regard for the order. Your suggestions will be highly appreciated!

例如,给定向量[‘aa’,‘bb’]和[‘cc’,‘dd’],期望的结果是[‘aAcc’,‘aAdd’,‘bbcc’,‘bbdd’],而不考虑顺序。我们将非常感谢您的建议!


更多回答
优秀答案推荐

vec1 = ['aa', 'bb'];
vec2 = ['cc', 'dd'];
result = cross(vec1, vec2);

result will contain ['aacc', 'aadd', 'bbcc', 'bbdd']

结果将包含[‘AACC’,‘aAdd’,‘bbcc’,‘bbdd’]



These two pages refer to the same thing (cross joins):

这两个页面引用相同的内容(交叉连接):


https://dolphindb.com/help/SQLStatements/TableJoiners/crossjoin.html?highlight=cartesian

Https://dolphindb.com/help/SQLStatements/TableJoiners/crossjoin.html?highlight=cartesian


https://dolphindb.com/help/FunctionsandCommands/FunctionReferences/c/cj.html?highlight=cartesian

Https://dolphindb.com/help/FunctionsandCommands/FunctionReferences/c/cj.html?highlight=cartesian


Example using cj()

使用CJ()的示例


a = table(2010 2011 2012 as year)
b = table(`IBM`C`AAPL as Ticker);
cj(a,b);

Result

结果


year  Ticker
2010 IBM
2010 C
2010 AAPL
2011 IBM
2011 C
2011 AAPL
2012 IBM
2012 C
2012 AAPL

Try this

尝尝这个


a = table(aa bb as x)
b = table(cc dd as y);
cj(a,b);

更多回答

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com