0

I wanted to interpret array indexing in the following code snippet. What does State[t,Con] mean, where Con itself is an array?

for t in range(T):  # 0 .. T-1
    State[t+1] = Bool[:, sum(Pow * State[t,Con],1)].diagonal()

And Con is given as below (where N>K):

Con = apply_along_axis(random.permutation, 1, tile(range(N), (N,1) ))[:, 0:K]

1 Answer 1

1

Con is a (N,K) array of integers.

State presumably is (T,N) array.

State[t,Con] will be a (N,K) array of values selected from the t row of State. Since Con has repeats, some values of the State row will be repeated.

`Bool[:, sum(Pow * State[t,Con],1)].diagonal()`

It then does a element by element multiplication with Pow (also a (N,K) array, or something compatible). Then sum over the last axis (columns), giving a N,) array (N element vector). Then select those columns from array Bool (a (N,N) array?). Finally get the main diagonal - again N values.

The last step is to assign those values to the t+1 row of State.

Sign up to request clarification or add additional context in comments.

2 Comments

Do you know how to translate this to matlab?
I'd have to experiment on my copy of Octave.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.