Hello Ric;

This thread seems to go around a J 'gotcha', the first I can recall which works this way, as opposed to things like #.^:_1 which work as you would expect them to, if you repressed your expectation of an error.

  M
6 5 9 2
4 9 0 7
0 4 6 8
3 8 1 2
  _((I. 0=,M)"_)}M
6 5 9 2
4 9 _ 7
_ 4 6 8
3 8 1 2
  _(I. 0=,M)}M
|index error
|   _    (I.0=,M)}M

Indices suggested by u in u}y are allowed to be in terms of the ravelled noun y, but those suggested by m in m}y cannot be.

Fortunately,

  x m"_ }v

is a valid workaround.  NB. My J epiphany of the day.

Sherlock, Ric wrote:
---Alex Rufon wrote:
What I want to do is to replace all zero in the matrix with infinity.

   ]M=: 4 [EMAIL PROTECTED]
6 5 9 2
4 9 0 7
0 4 6 8
3 8 1 2

amendZeros=: _&(([: I. 0 = ,@])})

   amendZeros M
6 5 9 2
4 9 _ 7
_ 4 6 8
3 8 1 2

Check out Chapter 6.3.3 Linear Indices in Learning J

----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm


--
------------------------------------------------------------------------
|\/| Randy A MacDonald       | APL: If you can say it, it's done.. (ram)
|/\| ramacd <at> nbnet.nb.ca |
|\ |                         | The only real problem with APL is that
BSc(Math) UNBF'83            | it is "still ahead of its time."
Sapere Aude                  |     - Morten Kromberg
Natural Born APL'er          |
-----------------------------------------------------(INTP)----{ gnat }-



----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to