我有这段代码。
START_STAT =(
[ 4, 3, 6, 3, ],
[ 3, 3, 4, 6, ],
[ 3, 5, 5, 3, ],
[ 4, 6, 3, 3, ],
[ 4, 3, 6, 3, ],
[ 3, 3, 4, 6, ],
[ 3, 5, 5, 3, ],
[ 4, 6, 3, 3, ],
)
我想用一行更新一行
START_STAT.update{[ 6, 2, 2, 6, ]}
那里有什么问题? 我也试过+但同样的错误。
START_STAT +={[ 6, 2, 2, 6, ]}
有什么问题?
答案 0 :(得分:2)
START_STAT =(..)
元组是immutable
。
您可以将list
用于此目的:
START_STAT = []
START_STAT.append([ 6, 2, 2, 6, ])
答案 1 :(得分:1)
如果您使用list
代替dict
,如Xi_所示,那么您也可以这样做:
import numpy as np
START_STAT =(
[ 4, 3, 6, 3, ],
[ 3, 3, 4, 6, ],
[ 3, 5, 5, 3, ],
[ 4, 6, 3, 3, ],
[ 4, 3, 6, 3, ],
[ 3, 3, 4, 6, ],
[ 3, 5, 5, 3, ],
[ 4, 6, 3, 3, ],
)
lst = ([ 6, 2, 2, 6, ])
np.vstack((START_STAT,lst))