That's not a good description, but there's more below.

First, thanks so much to those who suggested the box display in addition to linear. That has helped so much.

Here's what I want:

I want to take a rank 2 array and for each row in it: if the row contains no zeroes, leave it alone; if the row contains zeroes, then for each zero replicate the row and replace the instances of that zero with _1 and 1. This should repeat, so this:

1 _1  0  1
1  1 _1  1
0  1  0 _1

would become this:

 1 _1 _1  1
 1 _1  1  1
 1  1 _1  1
_1  1 _1 _1
_1  1  1 _1
 1  1 _1 _1
 1  1  1 _1

I've gotten close:

expandZeroes =: (_1 1 (] i.&0)}"0 1 ])[EMAIL PROTECTED](# = i.&0)"1

That produces:

 1 _1 _1  1
 1 _1  1  1

 1  1 _1  1
 0  0  0  0

_1  1  0 _1
 1  1  0 _1

And, applied twice it works perfectly on the third row. My intent is to add ^:_ to account for any number of zeroes, but doing that with the spurious row of zeroes in the above result would be bad...

So two questions:

First, correct me if I'm wrong, but if the output from each input row was shaped 2 4 instead of 1 2 4 I'd be set. The extra row of zeroes in the output is just a framing fill, correct? If that's so, how do I change the shape of the intermediate output?

Second, am I just going about this the wrong way? Is expandZeroes at all reasonable? Is there a better way?

Thanks,

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

Reply via email to