Here are some more simple examples that may help.
]B=: i. 4 5
0 1 2 3 4
5 6 7 8 9
10 11 12 13 14
15 16 17 18 19
1 3{ i. 4 5 NB. items 1 and 3 of B
5 6 7 8 9
15 16 17 18 19
(<1 3){ B NB. item 3 from item 1 of B
8
(1 3;3 3){ B NB. item 3 from item 1 of B & item 3 from item 3 of B
8 18
(<1 3; 3){ B NB. item 3 from items 1 & 3 of B
8 18
(<3;2 3){ B NB. items 2 & 3 from item 3 of B
17 18
(<1 3;2 3){ B NB. items 2 & 3 from items 1 & 3 of B
7 8
17 18
(<a:;2 3){ B NB. items 2 & 3 from all items of B
2 3
7 8
12 13
17 18
To amend the arrays, replace { with } and add a left argument that
matches the shape and type of the result you get using { .
(98 99) (1 3;3 3)} B
0 1 2 3 4
5 6 7 98 9
10 11 12 13 14
15 16 17 99 19
(90 + i.2 2) (<1 3;2 3)} B
0 1 2 3 4
5 6 90 91 9
10 11 12 13 14
15 16 92 93 19
On Wed, Feb 29, 2012 at 5:49 PM, PackRat <[email protected]> wrote:
> I have a table "b" (example below) which is the transpose of table "a"
> which is read in from a file. Here's what table b looks like, just so
> you have an idea of what's where:
>
> +--------+-----------+--------+--------+-----------+...
> |F |CAT |DE |CSX |XOM |...
> +--------+-----------+--------+--------+-----------+...
> |Ford |Caterpillar|Deere |CSX |Exxon Mobil|...
> +--------+-----------+--------+--------+-----------+...
> |3710 |665 |410 |890 |4000 |...
> +--------+-----------+--------+--------+-----------+...
> |19560307|19291202 |19330609|19801103|19991201 |...
> +--------+-----------+--------+--------+-----------+...
> |0 |0 |0 |0 |0 |...
> +--------+-----------+--------+--------+-----------+...
> |0 |0 |0 |0 |0 |...
> +--------+-----------+--------+--------+-----------+...
>
> The problem I'm having is with amending individual cells in both row 4
> and row 5 (the last two rows) of table b. (I've run into this problem
> before, but I created lengthy workarounds which are not really J-ish.
> I decided this time to ask the wisdom of the J community to finally
> find out once and for all what the "right" way of doing this kind of
> thing is.)
>
> I don't run into problems READING an individual cell, such as:
>
> stocksym=. toupper > (j { 0 { b)
>
> However, when I attempt to WRITE an amend into the jth (e.g., first)
> cell of row 4 of table b, for example:
>
> b=. (< stocknum) j } (4 { b)
>
> table b is incorrectly changed (compared to my intent, that is) from
> the table shown above to a list instead:
>
> +-+-+-+-+-+...
> |6|0|0|0|0|...
> +-+-+-+-+-+...
>
> Is there some "standard" way of making such amends within a table that
> I seem to be missing somewhere along the line? Thanks for your help!
>
>
> Harvey
>
> ----------------------------------------------------------------------
> For information about J forums see http://www.jsoftware.com/forums.htm
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm