Issue
I have 3 priors given minimum and maximum ranges. By using them, I need to create a NumPy array in the form of;
M = [[x_0, y_0, z_0], [x_1, y_1, z_1], ...,[x_N, y_N, z_N]]
where x=[0.60, 0.80]
, y=[1, 80]
, z=[0.022, 0.024]
how can I do this in a most efficient way (i.e., by least amount of code and by using NumPy) ?
Solution
it can be achieved by:
np.array([x, y, z]).T
some benchamrks:
size = 3 * 1000
50 loops, best of 5: 8.14 µs per loop # np.vstack
50 loops, best of 5: 2.95 µs per loop # this answer
size = 3 * 10000
50 loops, best of 5: 27.3 µs per loop
50 loops, best of 5: 19.9 µs per loop
size = 3 * 100000
50 loops, best of 5: 383 µs per loop
50 loops, best of 5: 359 µs per loop
size = 3 * 1000000
50 loops, best of 5: 5.23 ms per loop
50 loops, best of 5: 5.09 ms per loop
Answered By - Ali_Sh
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.