Rho: Difference between revisions

From NARS2000
Jump to navigationJump to search
No edit summary
(t/c)
 
(7 intermediate revisions by 3 users not shown)
Line 1: Line 1:
__NOTOC__
__NOTOC__
<h1> {rho} &mdash; Shape or Reshape &mdash; Keystroke ALT+r &mdash; Character 9076</h1>
 
{{Article header
|sym={rho}
|def=Shape or Reshape
|ks=ALT+r
|char=9076 or x2374
|kb=APLKB-Rho.png|kb2=}}
 
Note: This is ALT+r; ALT+SHIFT+R will generate the symbol [[Symbol Root|root]] ({root}).
Note: This is ALT+r; ALT+SHIFT+R will generate the symbol [[Symbol Root|root]] ({root}).


[[File:APLKB-Rho.png]]
Rho may be used as a [[monadic]] or [[dyadic]] operator, depending on the functionality desired. Used monadically with the argument to the right returns the '''shape''' of the argument. Used dyadically, the argument on the left is used to '''reshape''' the argument on the right.
==Reshape==
 
==Shape - Monadic {rho}==
<big>Symbol '''{rho}''' when used '''monadically''' (no left argument) returns the '''shape of {rho}'s right argument''', i.e. the size or dimensions of a scalar, string, vector, array or matrix. Shape returns null for a scalar or a single character, it returns 0 for a null string, the length of a string of at least two characters, the number of elements of an array or vector, and the number of elements of a matrix.</big>
<apll><pre>
      ⍴ 1 2 3 4 5 6    ⍝ Rho in the case of vectors represents a Count(# elements) function
6
      ⍴'abcdefg'      ⍝ Similarly with text strings(vector of chars), Rho represents a Count function
7
      ⍴ 1              ⍝ For a scalar right argument, Rho generates a null vector.
 
      ⍴⍴ 1            ⍝ The shape of the shape(⍴⍴) of a scalar (because the shape of a scalar is a null) - generates zero.
0
      ⍴ 'a'            ⍝ Ditto for {numbers, integers, letters}, etc. - for scalar right arguments: Rho also generates a null vector.
 
      ⍴⍴ 'a'
0
      ⍴, 4.581        ⍝ Rho for a raveled(, or comma used) scalar(real num 4.581) - again correctly represents a Count(# elements) function
1
 
      2 3⍴⍳6          ⍝ Dyadic call for demonstration purposes(see below for dyadic calls to {rho}): result = 2 rows and 3 cols matrix of integers(1..6)
1 2 3
4 5 6
 
      ⍴2 3⍴⍳6        ⍝ Monadic LEFTMOST shape {rho} yields: matrix has 2 rows and 3 cols; equivalent to ⍴(2 3⍴⍳6) which has parentheses added for clarity
2 3
 
      ⍴⍴(2 3⍴⍳6)      ⍝ Monadic LEFTMOST shape-shape or {rho}{rho} generates the RANK of the 2 row, 3 col matrix which = 2 (matrix)
2
      ⍴⍴(⍳6)        ⍝ Monadic leftmost {rho}{rho} generates the RANK of the vector = 1 (vector)
1
</pre></apll>
 
==Reshape - Dyadic {rho}==
<big>'''{rho}''''s Left Argument(L) output-reshapes {rho}'s Right Argument(R).</big>
<table border="1" cellpadding="5" cellspacing="0" rules="none" summary="">
<table border="1" cellpadding="5" cellspacing="0" rules="none" summary="">
<tr>
<tr>
Line 13: Line 53:
       <td></td>
       <td></td>
       <td></td>
       <td></td>
       <td>returns an array of shape <apll>L</apll> whose items are taken from <apll>R</apll> in row major order, repeated as necessary.</td>
       <td>dyadic '''{rho}''' returns an array of shape <apll>L</apll> whose items are taken from <apll>R</apll> in row major order, repeated as necessary.</td>
     </tr>
     </tr>
     </table>
     </table>
Line 26: Line 66:
</table>
</table>
<br />
<br />
<p>For example, in origin-1</p>
<p>For example, in origin <apll>1</apll> (where <apll>⎕IO=1</apll>)</p>


<apll>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;2 3⍴⍳6<br />
<apll><pre>
&nbsp;1 2 3<br />
      2 3⍴⍳6
&nbsp;4 5 6<br />
1 2 3
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;2 3⍴⍳0<br />
4 5 6
&nbsp;0 0 0<br />
      2 3⍴⍳0
&nbsp;0 0 0<br /></apll>
0 0 0
0 0 0</pre></apll>


<p>The idea for the latter enhancement was taken from Dyalog APL.</p>
<p>The idea for the latter enhancement was taken from Dyalog APL.</p>


==Shape==
{{article footer|8|Rho}}
The symbol {rho} used with no left argument returns the size or dimensions of a scalar, string, vector, array or matrix.
[[Category:Monadic operators]]
 
[[Category:Dyadic operators]]
{{article footer}
[[Category:Monadic Operators]]
[[Category:Dyadic Operators]]
 
==See Also==
 
 
 
{{Language Toolbar}}
[[Category:Mouse Group 8|R]]
[[Category:Symbols|R]]

Latest revision as of 18:00, 13 October 2019


⍴ — Shape or Reshape — Keystroke ALT+r — Character 9076 or x2374



Note: This is ALT+r; ALT+SHIFT+R will generate the symbol root (√).

Rho may be used as a monadic or dyadic operator, depending on the functionality desired. Used monadically with the argument to the right returns the shape of the argument. Used dyadically, the argument on the left is used to reshape the argument on the right.

Shape - Monadic ⍴

Symbol when used monadically (no left argument) returns the shape of ⍴'s right argument, i.e. the size or dimensions of a scalar, string, vector, array or matrix. Shape returns null for a scalar or a single character, it returns 0 for a null string, the length of a string of at least two characters, the number of elements of an array or vector, and the number of elements of a matrix.

      ⍴ 1 2 3 4 5 6    ⍝ Rho in the case of vectors represents a Count(# elements) function
6
      ⍴'abcdefg'       ⍝ Similarly with text strings(vector of chars), Rho represents a Count function
7
      ⍴ 1              ⍝ For a scalar right argument, Rho generates a null vector.

      ⍴⍴ 1             ⍝ The shape of the shape(⍴⍴) of a scalar (because the shape of a scalar is a null) - generates zero.
0
      ⍴ 'a'            ⍝ Ditto for {numbers, integers, letters}, etc. - for scalar right arguments: Rho also generates a null vector.

      ⍴⍴ 'a'
0
      ⍴, 4.581        ⍝ Rho for a raveled(, or comma used) scalar(real num 4.581) - again correctly represents a Count(# elements) function
1

      2 3⍴⍳6           ⍝ Dyadic call for demonstration purposes(see below for dyadic calls to ⍴): result = 2 rows and 3 cols matrix of integers(1..6)
1 2 3
4 5 6

      ⍴2 3⍴⍳6         ⍝ Monadic LEFTMOST shape ⍴ yields: matrix has 2 rows and 3 cols; equivalent to ⍴(2 3⍴⍳6) which has parentheses added for clarity
2 3

      ⍴⍴(2 3⍴⍳6)      ⍝ Monadic LEFTMOST shape-shape or ⍴⍴ generates the RANK of the 2 row, 3 col matrix which = 2 (matrix) 
2
      ⍴⍴(⍳6)         ⍝ Monadic leftmost ⍴⍴ generates the RANK of the vector = 1 (vector)
1

Reshape - Dyadic ⍴

⍴'s Left Argument(L) output-reshapes ⍴'s Right Argument(R).

Z←L⍴R dyadic returns an array of shape L whose items are taken from R in row major order, repeated as necessary.
L is a scalar or vector of non-negative integers, and R is an arbitrary array.
If the right argument is empty, the result consists of ×/⍴L copies of the fill item of R.


For example, in origin 1 (where ⎕IO=1)

      2 3⍴⍳6
 1 2 3
 4 5 6
      2 3⍴⍳0
 0 0 0
 0 0 0

The idea for the latter enhancement was taken from Dyalog APL.


See Also
System Commands System Variables and Functions Operators


Keyboard
Alt+Shift
Alt ¨ ¯ < > × ÷
Shift ~ ! @ # $ % ^ & * ( ) _ +
Key ` 1 2 3 4 5 6 7 8 9 0 - =
Alt+Shift
Alt ? § π
Shift Q W E R T Y U I O P { } |
Key q w e r t y u i o p [ ] \
Alt+Shift
Alt
Shift A S D F G H J K L : "
Key a s d f g h j k l ; '
Alt+Shift χ
Alt
Shift Z X C V B N M < > ?
Key z x c v b n m , . /
NARS 2000 Lang
Tool
Bar
+ - × ÷ * ! ? |
< = >
~ § π .. ,
/ \ ¨ .
_ ¯
Second Row i j k i j k l g p r v x