1I am currently using a structured array to save some measurements from a sensor. The array (named "data") is of the dimension 2000x3 with the three fields: "samples", "timestamp" and "labels", where samples is a vector of 6 elements. For example, one row looks like this:
([-19.837763650963275, -19.61692779005053, -18.5301618270122, -13.413484985874076, -13.192649124961326, -12.105883161923], 0.0, 0)
[('samples', '<f8', (6,)), ('timestamp', '<f8'), ('labels', '<i4')]
If I now want to have all samples of one row i could access the row like this:
data["samples"][10]
which works fine but if i turn it around and write it like this:
data[10]["samples"]
I get the following error:
ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()
Does anyone know why this is happening?
EDIT: For a better understanding here are the first 10 rows of the "data" array:
[ ([-19.837763650963275, -19.61692779005053, -18.5301618270122, -13.413484985874076, -13.192649124961326, -12.105883161923], 0.0, 0) ([-18.66282477705446, -18.449317421024432, -17.369283339067675, -12.357118609142269, -12.145937637117552, -11.068086720774204], 0.0, 0) ([-17.69388207920866, -17.49198382816449, -16.417085567075173, -11.53193799727324, -11.33976221074188, -10.268890664091229], 0.0, 0) ([-16.868088042481606, -16.683019283158636, -15.610803357043569, -10.88697503359368, -10.732729221349611, -9.663174869208511], 0.0, 0) ([-16.152597338007514, -15.99074244228478, -14.917542852993487, -10.420257243109129, -10.371835643625495, -9.274470774420056], 0.0, 0) ([-15.527885804583931, -15.39736918876727, -14.317660328685264, -10.451759205557037, -10.011944429521288, -9.006031495483906], 0.0, 0) ([-14.981993405744573, -14.894234811642814, -13.799157258392123, -10.01393043959338, -9.563854671143899, -8.587392657229502], 0.0, 0) ([-14.508475562047407, -14.48315918653869, -13.355984261155621, -9.577456476813333, -9.16920566037696, -8.205174149255923], 0.0, 0) ([-14.106856958780497, -14.199089434545343, -12.989626950396643, -9.214711746255777, -8.944244361010687, -7.942834820090279], 0.0, 0) ([-13.789298779585817, -13.943732248940886, -12.72321280228509, -9.208476598556874, -8.629970466866272, -7.690122078593869], 0.0, 0)]
EDIT 2: I'm using numpy version 1.10.4
And I'm actually not using
data[0]["samples"]
but I tried it and it doesn't work as well. I'm using it this way:
for row in data: print(row["samples"])
I did the most basic example that I could think of and it this works surprisingly:
I did the most basic example that I could think of and it this works surprisingly:
a = np.zeros(10, dtype = [("a", "5f8"), ("b", "i4")])
print(a["a"][5]) # Works
print(a[5]["a"]) # Surprisingly works as well