python - Numpy vectorized less than/greater than comparisons -
I have some code that they meet the quadrangle of the circle which they fall. It currently gives me the results that I want, but I am trying to lose the loop to make full use of the numpy speed. The fourth part of each circle is the center of spawn_angles = np.array ([3, 10, 80, 100, 170, 190, 260, 280]).
np angle = np.array 0, 90, 180, 270]) segment_degrees = np.diff (spawn_angles) [0] lower_bounds = spawn_angles - (segment_degrees / 2) upper_bounds = spawn_angles + (segment_degrees / 2) max_upper = upper_bounds.max () # Wrap back negative Angle angle angle angle greater than the upper limit of angle & gt; Max_upper] = = 4th part of the 360-quad = np.zeros_like (angle, dtype = np.float64) # that fourth part that does not get calculated # Just want to ensure invalid numbers will be assigned, i.e. -1 quadrant.fill (-1) For segment_num (lane (spawn_angles)) in range: in_segment = (; lower_bounds [segment_num]) & amp; (Angle & lt; (angle & gt upper_bounds [segment_num])) quadrant [in_segment] = segment_num # required / current output quadrant out [16]: Array ([0, 0, 1. , 1., 2., 2., 3., 3.])
Actually, in which part I can not understand how to do samples, it is & gt;
/ & lt;
than the angle lower_bounds [0]
and upper_bounds [0]
, handed circle the quadrant between the entry
, then is 0, and similar to the quadrant 1, 2, 3. is there any way AIDS Array to LOWER_BOUND
and / or Upri_bound
as well as all entries To compare?
(If this code seems to have some of that, because overcomplicated spawn_angles
/ are not always quadrant centers circle [0, 90, 180, 270]
, they may also be like [45, 135, 225, 315]
)
You need to lift everything up to one dimension. You want a 2D array with each segment_num as a line and as a column for each angle (or you may want to make a transfer), but if so, you are able to remove it from here. Should be.)
If you just click a & gt; B
where one
and b
are both 1D arrays, you are comparing 1 to 1 element.
But if a
is a 2D array, then you are asking for a comparison of the Cartesian product.
In other words:
& gt; & Gt; & Gt; Array Fresh ((8,1)) & gt; Nicla_bound Array ([True, True, True], [true, false, false, false], [true, false, false] true, true, false, false, true, true
and you should be able to understand it from there.
< / Div>
Comments
Post a Comment