I assume that this behavior is for performance reasons, as to not scan for
zero's when not needed.

The dictionary says: "8&$. removes any rows where the value equals the zero
element" , so

BID =: 8$.BID

gets rid of the the element at index 10.

Jan-Pieter


2014-05-21 11:18 GMT+02:00 'Scott Locklin' via Programming <
[email protected]>:

> So, I have never used sparse arrays in J before, and am puzzled by some of
> the behavior.
> If I initialize an integer sparse vector BID, and set element 10 to be 90:
>
> BID=: 1 $. 100;0;3-3
> BID=: (90) 10}BID
>   BID
> 10 │ 90
>
>
> Cool;  but then, if I want to zero out the 10 element
>
> BID=: (90-90) 10}BID
>    BID
> 10 │ 0
>
>
> Not cool; especially when I want to use 4&$. to find the nonzero elements:
>    4&$.BID
> 10
>
>
> Am I expecting too much from sparse vectors? Or am I assuming something
> silly? FWIIW, I checked on 702 and 801; same behavior. Was trying to use
> sparse vectors as a sort of numeric keyed hash table. It's probably not
> much use doing this if the 0 valued elements return an index with 4&$.
> Thanks for any insights,
>
> -Scott
> ----------------------------------------------------------------------
> For information about J forums see http://www.jsoftware.com/forums.htm
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to