简体   繁体   中英

Putting sess.run output into a list

So my code has the line in it and it works:

    _, loss_value0, loss_value1, loss_value2, loss_value3 = sess.run([train_op, loss0, loss1, loss2, loss3])

I wanted to make this a list of losses so I ran:

    loss_value_list = []
    _, loss_value_list = sess.run([train_op] + loss_list)

But that doesn't work. Probably I can't assign a list like that? Is there someway to do that?

Thanks for any help!

No need to pre define the loss_value_list ; Use * operator to unpack the result into a list variable instead:

lst = ['a', 1, 2, 3, 4]
_, *loss_value_list = lst

loss_value_list
# [1, 2, 3, 4]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM