[英]Force array instead of matrix in J for “i.”
The i.
i.
primitive produces a list of integers: primitive生成一个整数列表:
i. 10
0 1 2 3 4 5 6 7 8 9
If I want to produce several short lists in a row, I do this: 如果我想连续生成几个短列表,我这样做:
;i."0 each [ 2 3 4
0 1 0 1 2 0 1 2 3
(the result I want) (我想要的结果)
Boxing (that each
) is a crutch here, because without it, i."0
produces a matrix. 拳击(
each
)在这里是一个拐杖,因为没有它, i."0
产生一个矩阵。
i."0 [ 2 3 4
0 1 0 0
0 1 2 0
0 1 2 3
(the result I don't want) (我不想要的结果)
Is there a better way to not have i."0
format the output to a matrix, but an array? 有没有更好的方法没有
i."0
格式输出矩阵,但数组?
No, I believe you can't do any better than your current solution. 不,我相信你不能比现有的解决方案做得更好。 There is no way for
i."0
to return a vector. 我没办法
i."0
返回一个向量。
The "0
adverb forces i.
to accept scalars, and i.
returns vectors. i.
has no way of knowing that your input was a vector rather than a scalar. According to The J primer the result shape is the concatenation of the frame of the argument and the result. "0
副词强迫i.
接受标量,而i.
返回向量。 i.
无法知道你的输入是一个向量而不是一个标量。根据The J的引子 ,结果形状是框架的连接。论证和结果。
The shortest "box-less" solution I've found so far is 到目前为止我找到的最短的“无盒子”解决方案是
(*@$"0~#&,i."0) 2 3 4
which is still longer than just using ;i. each 2 3 4
这仍然比使用更长
;i. each 2 3 4
;i. each 2 3 4
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.