Python打印错误:%d格式:需要数字,而不是元组

way*_*tir 4 python numpy ipython typeerror

当我尝试打印时出现意外错误:

import numpy as np
a = np.array([11, 21, 31, 41, 51])
it = np.nditer(a, flags=['multi_index'], op_flags=['readwrite'])

while not it.finished:
    i = it.multi_index
    print("%d %d" % (i, a[i]))
    it.iternext()
Run Code Online (Sandbox Code Playgroud)

此代码生成错误:

TypeError: %d format: a number is required, not tuple
Run Code Online (Sandbox Code Playgroud)

但是当我简单地这样做时:

for i in xrange(5):
    print("%d %d" % (i, a[i]))
Run Code Online (Sandbox Code Playgroud)

然后我得到预期的结果:

0 11
1 21
2 31
3 41
4 51
Run Code Online (Sandbox Code Playgroud)

那么为什么在之前的情况下会出现此错误呢?

Cor*_*den 5

i不是一个数字。

In [69]: it.multi_index
Out[69]: (0,)
Run Code Online (Sandbox Code Playgroud)

i[0]代替使用。