I have a np.ndarray
(call it arr
) that looks something like this:
# python 3.7
import numpy as np
my_dtype = [("x", "float32"), ("y", "float32"),
("some_more", "int32"), ("and_more_stuff", "uint8")] #
part1 = np.zeros(5, dtype=my_dtype) # various lengths (here e.g. 5, 6 and 7)
part2 = np.zeros(6, dtype=my_dtype)
part3 = np.zeros(7, dtype=my_dtype)
# ... an a priori unknown number of "parts". Also of course there are values inside, not just zeros.
arr = np.array([part1, part2, part3])
(maybe I should not use numpy arrays to handle such data?)
Now I want to do things with arr
. For example I want to find the total minimum among all values "x" and "y" in all subarrays (a single number). My solution looks fairly horrible which means that I don't understand how to use structured arrays (despite reading the documentation and the official tutorial):
arr[0][["x", "y"]][1] = (-3., 4.5) # put in some values as an example
all_x_y_coords= np.array([[list(mytuple) for mytuple in mylist] for mylist in
[list(part[["x", "y"]]) for part in arr]])
print(np.min(np.min(all_x_y_coords))) # gives -3. as desired, but at what cost?!
Doing something like this is clearly not practical. How would one calculate the minimum that I want? The next thing I would like to do is apply a rotation matrix to all "x,y". Before I concoct something even more horrible than the code above I thought I had better understand what I'm doing wrong. Thank you very much in advance for any help!