Aizzaac
Aizzaac

Reputation: 3318

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

I have a file which I had converted into an array. File looks like this:

enter image description here

When I print results I get these values:

# 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]

Example A prints the good results. But Example B no. Why? What do I have to google to know the answer?

Upvotes: 1

Views: 70

Answers (1)

Ivan
Ivan

Reputation: 40628

You are indexing array a (it's also gift_costs) with itself, i.e. the resulting array b would be characterized by this loop:

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

Upvotes: 2

Related Questions