Lots of replies already to your main question.
As for
"Another question is how to fill the table with values depending
on indexes of cell? For example, F[i,j,k] = (i * j) - (i * k) + (j * k) ":
As Henry says, you might not in practice need the whole index array;
you also might not need to populate the whole array of values.
But here is one quite straightforward way to do so if you do need to.
You say you want i j k to be index vectors, but they could be any
old vectors, so how about
'i j k' =: 1 3;2 7 11; 4 6 10 NB. set up 3 vectors with lengths 2
3 3
NB. take item 1 1 0 in F[i,j,k]
(<1 1 0){(i*/j*/k=k) - (i */(j=j) */ k) + (i=i)*/ j */ k
_19
NB. slightly less computation, (i*j-k) - j*k
(<1 1 0){(i*/j-/ k) - (i=i)*/ j */ k
_19
NB. alternatively, use 0 in the first vector with add:
(<1 1 0){(i*/j-/ k) - (i-i)+/ j */ k
_19
NB. demonstrate it's the right result...
1 1 0 {every 1 3;2 7 11; 4 6 10
3 7 4
(3 * 7) - (3 * 4) + 7 * 4
_19
NB. or (i*j-k) - j*k
(3 * 7 - 4) - 7 * 4
_19
I'm assuming J/APL evaluation order, where (a - b + c) -: a - (b + c)
Mike
On 04/04/2015 22:09, Sergeif wrote:
Hi.
How can someone create list of indexes of 3d table (N x M x K)?
I have written this simple code:
ind3d =: 3 : 0
'n m k' =. y
p0 =. k&|
p1 =. (m&|)@:<.@:(%&k)
p2 =. <.@:(%&(m*k))
(p2 , p1 , p0)"0 (i. (n*m*k))
)
but it's very very slow. Does any tacit solution for this problem exist?
Another question is how to fill the table with values depending on indexes
of cell? For example, F[i,j,k] = (i * j) - (i * k) + (j * k).
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm
---
This email has been checked for viruses by Avast antivirus software.
http://www.avast.com
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm