In J , I have a list like 1 2 3 , I want to take *: and 2* to make it a box structure like
J
1 2 3
*:
2*
┌─┬─┐ │1│2│ │4│4│ │9│6│ └─┴─┘
or even
┌───┐ │1 2│ ├───┤ │4 4│ ├───┤ │9 6│ └───┘
How to do it? I would really appreciate your help.
You need to call gerund in add mode ( :0 ).
:0
a =: 1 2 3 *:`+: (`:0) a 1 4 9 2 4 6
If you need them in a box, simply ;/ them:
;/
;/*:`+: (`:0) a ┌─────┬─────┐ │1 4 9│2 4 6│ └─────┴─────┘ ;/ |: *:`+: (`:0) a NB. different axis ┌───┬───┬───┐ │1 2│4 4│9 6│ └───┴───┴───┘ _3 <\6 1 $,*:`+: (`:0) a NB. yet another axis ┌─┬─┐ │1│2│ │4│4│ │9│6│ └─┴─┘
If you need vertical (column-oriented) output, you must first convert your list to vertical (in the column) format:
,.1 2 3 1 2 3
Now you can apply as many calculations as you want. If you want to put each output in a separate block, you can link them together using; in a fork:
(*: ; 2&*) ,. 1 2 3
Two notes:
It is optional and not necessary to use fields in J when all your data is of the same type and shape. In your case, both of your operations are scalar and numeric, so both verbs will generate a column of 1x3 numbers. It would be more typical and idiomatic to combine them with,. to create a 2x3 digit table than ; to create 2 opaque blocks.
;
The "double" is already primitive in J, so instead of 2&* we can say +: as in (*: ; +:) ,. 1 2 3 (*: ; +:) ,. 1 2 3
2&*
+:
(*: ; +:) ,. 1 2 3
Source: https://habr.com/ru/post/1492506/More articles:Why is PrintStream extending FilterOutputStream and not OutputStream? - javaDefine a NEW navigation bar frame BEFORE THE BEGINNING of the actual rotation - iOS - user-interfaceHow to display and process visual objects in a web application? - javascriptWhat is the data format for publishing data from a Vantage Pro 2 weather station? - json$ .parseJSON not working in Internet Explorer 10 - jsonGridBagLayout: how to fill all empty spaces - javahttps://translate.googleusercontent.com/translate_c?depth=1&rurl=translate.google.com&sl=ru&sp=nmt4&tl=en&u=https://fooobar.com/questions/1492508/maven-release-plugin-pushing-tags-to-wrong-repo&usg=ALkJrhiGPxfT2SiILohReMAV0FDBWlM6LwAdding a path (BezierSegment to a) to the canvas - c #MatPlotLib plot_surface: hidden lines appearing in a PDF file - pythonR - Processing of cut intervals of the form [x, y] in tables during conversion to LaTeX - rAll Articles