如何用数组中的字符串替换空值(python)?

时间:2016-01-19 20:39:31

标签: python arrays python-2.7

我想在我的阵列中输入玩家的名字。我将数组设置为空,现在我如何将用户给出的名称放入数组?

1.到目前为止,这是我的编码:

def randName(team_names):
    team_names = list(team_names)
    shuffle(team_names)
    leftover = team_names.pop() if len(team_names) % 2 else None
    trick = [iter(team_names)] * 2
    pairs = list(zip(*trick))
    return pairs, leftover

teamNames = []
name = ""

while name != "end":
    name = raw_input ("Enter the name of an opponent: (end to exit)")
    teamNames.append(name)

teamNames.pop()

chart = np.empty((len(teamNames)/2,2), dtype=np.str)

print chart

1 个答案:

答案 0 :(得分:0)

在numpy中,您可以通过引用要更改的元素的索引来更改数组的值,例如:

    chart[0,1] = 'Name'