Ben Gorte asked:
> Am I supposed to see zeroes when I look at a
> sparse array, after amend?
Yes, that's the expected behavior. There's somewhat lengthier discussion of
this topic at [1], but the short story is J does not constantly or
automatically removed zeros from sparse arrays; it only does so on command
(as when you create the array, or use 8&$., etc). Furthermore, there are
several ways to introduce zeros into your sparse array, and some of them are
less obvious and more prone to accident than explicit amendment (e.g.
increasing the rank of the array).
> ]m =: 1 0 0 (1 1;2 2;3 3) } $. 4 4$0
At least in the case of amendment, you do have some recourse, since you
control everything. For example, you could use a cover for } that simply
removes 0s from x and the corresponding indices from m first:
M =: 1 : (':';' (z#x) (m#~z=.x~:0)} y')
]m =: 1 0 0 (1 1;2 2;3 3) 'M' f. $. 4 4$0
1 1 │ 1
But since it would be non-trivial to make this cover general (right now it
only covers vector x and Cartesian [atomically-specified] m), it might be
better and even more efficient to take the easy route and apply 8&$. .
]m =: 8 $. 1 0 0 (1 1;2 2;3 3) } $. 4 4$0
1 1 │ 1
-Dan
[1] On introducing zeros into sparse arrays:
http://www.jsoftware.com/pipermail/programming/2007-May/006468.html
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm