Home > Blockchain >  Creating a numpy matrix from given min and max priors
Creating a numpy matrix from given min and max priors

Time:07-01

I have 3 priors given min 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) ?

CodePudding user response:

import numpy as np

N = 4
xs = np.random.uniform(x[0], x[1], size=N)
ys = np.random.uniform(y[0], y[1], size=N)
zs = np.random.uniform(z[0], z[1], size=N)

res = np.vstack((xs,ys,zs)).transpose()

Example with numbers

N = 4
xs = np.random.uniform(0.6, 1.1, size=N)
ys = np.random.uniform(3, 5, size=N)
zs = np.random.uniform(8, 9, size=N)
res = np.vstack((xs,ys,zs))
res.transpose()
# array([[0.88860867, 3.11233047, 8.26189772],
#        [0.70096631, 4.984737  , 8.01999442],
#        [1.08111807, 3.54934757, 8.28137655],
#        [1.04116942, 3.16903737, 8.12647381]])

CodePudding user response:

it can be achieved by:

np.array([x, y, z]).T
  • Related