-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 ?

khelwood
  • 55,782
  • 14
  • 81
  • 108
honolulu
  • 17
  • 1
  • 1
    Running your code I get following sequence of execution (assuming `numpy` was imported): A NameError in line 4, then the execution stops. – Michael Szczesny Feb 19 '22 at 08:07

1 Answers1

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)
Gal Toubul
  • 61
  • 3
  • does the sequence of for loops matter or they could be run in any sequence ? – honolulu Feb 19 '22 at 08:26
  • 1
    @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. – Pychopath Feb 19 '22 at 08:35