$ y (Shape Of)

Back to: Vocabulary

Returns the shape of the noun y .

The shape of a given noun is...

   $ y=: 'a'

   $ $ y   
0
   (i.0) -:  $ y=: 'a'
1

   $ y=: 'abcdefghijkl'
12

   ] y=: 'abc' ,: 'def'
abc
def
   $ y
2 3

Warning Shape Of ($) behaves differently to Tally (#) (which counts the items in a list).

   ($ ; #) y=: ''
+-+-+
|0|0|
+-+-+
   ($ ; #) y=: 'a'
++-+
||1|
++-+
   ($ ; #) y=: ,'a'
+-+-+
|1|1|
+-+-+
   ($ ; #) y=: 'abc'
+-+-+
|3|3|
+-+-+

Common uses

1. To verify if a noun is empty, an atom, or a list.

   $ y=: ''
0
   $ y=: 'a'

   $ y=: ,'a'
1
   $ y=: ,'abc'
3

2. To check that two matrices have the same number of entries in the same arrangement.

   ] y=: 2 3 $ 'abcdef'
abc
def
   ] x=: 4 5 $ 'ABCDEF'
ABCDE
FABCD
EFABC
DEFAB

   $ x,y
6 5
   $ x,:y
2 4 5
   $ x,.y
|length error
|   $x    ,.y
   $ x,.x
4 10

See Also


x $ y (Shape)

Back to: Vocabulary

Changes the Shape Of ($) (or re-shapes) the array y to (a vector derived from) x.

   $ y=: 'abcdefghijkl'
12
   ] z=: 2 2 $ y
ab
cd
   $ z
2 2

Warning the resulting Shape Of z ($z -- where z=:x$y)) is not necessarily x unless the items of y are atoms!

   y=: 'abcdefghijkl'
   $ z=: 2 2 $ y
2 2
   y=: 3 4$'abcdefghijkl'
   $ z=: 2 2 $ y
2 2 4

Common uses

1. To create a matrix from a unidimensional list.

2. To change the arrangement of entries in a matrix.

See Also


CategoryVoc

Vocabulary/dollar (last edited 2012-02-26 14:39:56 by IanClark)