When using numpy named arrays I observe a different behaviour in the following two cases:
- case: first using an index array for advanced slicing and then selecting a subarray by name
- case: first selecting a subarray by name and then using an index array for advanced slicing
The follwing code presents an example
import numpy as np
a = np.ones(5)
data = np.array(zip(a, a, a), dtype=[("x", float), ("y", float), ("z", float)])
# case 1
# does not set elements 1, 3 and 4 of data to 22
data[[1, 3, 4]]["y"] = 22
print data["y"] # -> [ 1. 1. 1. 1. 1.]
# case 2
# set elements 1, 3 and 4 of data to 22
data["y"][[1, 3, 4]] = 22
print data["y"] # -> [ 1. 22. 1. 22. 22.]
The output of the two print commands is [ 1. 1. 1. 1. 1.] and [ 1. 22. 1. 22. 22.]. Why does changing the order of the selections lead to different results when setting the elements?