-2
a = np.array(
    [
        [
            [
                get_score(weights[i][k], vec, y)
                for vec in get_vector()
            ]
            for k in range(x)
        ]
        for i in range(y)
    ]
)

How is the execution sequence in this code ?

1
  • 1
    Running your code I get following sequence of execution (assuming numpy was imported): A NameError in line 4, then the execution stops. Commented Feb 19, 2022 at 8:07

1 Answer 1

3

It is eqivalent to this:

a = []
for i in range(y):
    for k in range(x):
        for vec in get_vector():
            a.append(get_score(weights[i][k], vec, y))
a = np.array(a)
Sign up to request clarification or add additional context in comments.

2 Comments

does the sequence of for loops matter or they could be run in any sequence ?
@honolulu Well try different sequences, and you'll see it matters. You'll also see that this is obviously not equivalent (builds a 1D structure instead of a 3D structure) and that it's a mystery how this got two upvotes.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.