accumulate迭代结果可以是多个vector吗

我想实现类似这样的一个功能:输入[1,2,3,4],得到结果[1], [1,2], [1,2,3], [1,2,3,4]

但这么写会产生报错

代码:accumulate(def(a,b){v=iif(form(a)==0,[a],a);v.append!(b);return v},[1f,2f,3f,4f])

报错:"A scalar object is expectd.But the actual object is a vector."

accumulate每次迭代结果必须是scalar,不能是vector吗? 

请问该如何解决呢

请先 登录 后评论

1 个回答

Junny

目前版本的accumulate对于array of arrays的支持有一定的局限性。你可以这样写实现这个需求:

init = array(DOUBLE, 0) // must be a vector
v = (1.0, 2.0, 3.0, 4.0) // must be a tuple
accumulate(def(a, b){c=a;c.append!(b);return c}, v, init)

下周将发布的DolphinDB 2.00.9和1.30.21版本没有这方面的限制。

请先 登录 后评论
  • 1 关注
  • 0 收藏,712 浏览
  • levenew 提出于 2023-02-09 18:40