Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
如何计算 APL 中向量中 n 个相邻数字的平均向量?
考虑向量: a← 2 3 4 5 6
输入: 2 应该返回 2.5 3.5 4.5 5.5,
3 应该返回 3 4 5,
4 应该返回 3.5 4.5。
avg←(+/a)÷⍴a 在这种情况下无济于事!
使用 n 次归约得到总和,然后除以:
f←{(⍺+/⍵)÷⍺} 2 f 1 2 3 4 5 1.5 2.5 3.5 4.5 3 f 1 2 3 4 5 2 3 4 4 f 1 2 3 4 5 2.5 3.5
糟糕,现在有了您的确切输入:
f←{(⍺+/⍵)÷⍺} 2 f 2 3 4 5 6 2.5 3.5 4.5 5.5 3 f 2 3 4 5 6 3 4 5 4 f 2 3 4 5 6 3.5 4.5