I had a J program that I wrote in 1985 (on vax vms). One section created a diagonal matrix from a vector.
a=(n,n)R1,nR0 b=In a=bXa
Maybe it was not J, but APL in ascii, but these lines work in current J (with corresponding changes in primitive functions). But not in the APL (gnu, NARS2000, or ELI). I get a domain error in the last line. Is there an easy way to do this without a loop?
Your code is a transliteration of the ASCII APL. Corresponding J code:
a=.(n,n)$1,n$0 b=.i.n a=.b*a
! APL ( Dyalog APL) , . , b a :
b
a
a←(n,n)⍴1,n⍴0 b←⍳n a←b×[1]a
! ( ):
a←(n,n)⍴1,n⍴0 b←⍳n a←b(×⍤0 1)a
!
- ⍉ :
n←5 ◊ z←(n,n)⍴0 ◊ (1 1⍉z)←⍳n ◊ z 1 0 0 0 0 0 2 0 0 0 0 0 3 0 0 0 0 0 4 0 0 0 0 0 5
X, APL ( @Adám ):
X
(2⍴S)⍴((2×S)⍴1,-S←⍴X)\X
, .
, , ( ):
((⍴Q)⍴X)×Q←P∘.=P←⍳⍴X ((⍴Q)⍴X)×Q←P Pρ1,(P←≢X)ρ0
:
(n∘.=n)×(2ρρn)ρn←⍳5
should provide you with the following in most APL
1 0 0 0 0 0 2 0 0 0 0 0 3 0 0 0 0 0 4 0 0 0 0 0 5
This solution works in the old ISO Apl:
a←(n,n)⍴v,(n,n)⍴0
Source: https://habr.com/ru/post/1691470/More articles:Symfony Router redirects to http in https - httpR - combined fuzzy and exact match - matchingWhat does class deadlock mean? - javaASP.NET Core API sending double quoted string - c #Replace the item and the following items in the list if the condition is met - pythonThe click handler does not start when the target element is moved - angularHow can I use a class from a vendor folder in a laravel project - phpA built-in method of type "c" that returns the object it was called on - groovyReliable cross-platform way to get a method in Java - javaMy commits on GitHub are not from "my" user - gitAll Articles