문제
i.
프리미티브는 정수 목록을 생성합니다.
i. 10
0 1 2 3 4 5 6 7 8 9
.
연속으로 여러 개의 짧은 목록을 생성하고 싶다면 다음을 수행합니다.
;i."0 each [ 2 3 4
0 1 0 1 2 0 1 2 3
.
(내가 원하는 결과)
권투 (그 thereacodicetagode)는 여기에 없으므로 each
가 매트릭스를 생성합니다.
i."0 [ 2 3 4
0 1 0 0
0 1 2 0
0 1 2 3
.
(내가 원하지 않는 결과)
은 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.
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.
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
제휴하지 않습니다 StackOverflow