Numpy 数组显示与用于创建它的文件不同的结果

Numpy array display different results than the file that was used to create it

我有一个已转换为数组的文件。 文件如下所示:

当我打印结果时,我得到这些值:

# Example A

a=gift_costs
print(a)

[ 8 84 42 ... 59 12 12]


# Example B

b=gift_costs[gift_costs]
print(b)

[78 48 92 ... 80 23 23]

示例 A 打印出良好的结果。但是示例 B 没有。为什么?我必须 google 才能知道答案?

您正在用自身索引数组 a(它也是 gift_costs), 结果数组 b 的特点是循环:

for i in range(len(a)):
   b[i] = a[a[i]]