I am trying to learn how to manipulate tables of numbers in J coming from a
NumPy/Python background. Assuming *mat* is a 10x10 matrix, that's what I
have figured out so far:

- Replace values equal to 1 with 10
(mat e. 1) } mat ,: 10
- Replace all non-multiples of 5 with _
(-. 0 = mat |~ 5) } mat ,: _
- Multiply each column by its index
mat (*" 1) i. 10
- Multiply each row by its index
mat (*" 0) i. 10
- Replace the second column with 0
0 (1) }"1 mat
- Replace the second column with 0 (another way)
0 (< (i.10); 1 ) } mat
- Take the diagonal of the matrix
(<0 1)&|: mat

Now, there are some tasks that I can do in NumPy but haven't found how to
do in J. For instance:
- Add 1 to each value in the first column
x[:,1] += 1
- Add 1 to each value in the third row
x[3,:] += 1

In each of those cases, I am selecting the cells by their indexes rather
than their values, and am using the existing values to generate the new
ones. Is that possible in J?

I would also like to figure out how to modify nontrivial sequences of
indexes, for instance, diagonals or cells where both the row index and the
column index are even numbers. Where should I start if I want to do that
kind of thing?

Any suggestion would be highly appreciated.


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

Reply via email to