1

I'm trying to combine two merge values from two arrays to get one whole new array. However, I have no idea how to do.

I want to get a random float number for two variables like 5 times because I want to store them for future use. Hence, I used math.random but it doesn't work as expected because it will replace the variables.

Hence, I tried to get a randomized number and put it into an array. Then, I want to combine them to get one array. Each random number from each array are together.

import numpy as np

np.random.seed(42)

randomReleaseAngle = np.empty(5)
randomVelocity = np.empty(5)

for i in range(5):
    randomReleaseAngle[i] = np.random.uniform(20.0, 77.0 )
    randomVelocity[i] = np.random.uniform(40.0, 60.0 )

print(randomReleaseAngle)
print(randomVelocity)

I wanted to get something like this:

[[41.34,51.72], [28.86,45.31], [54.26,44.23], [64.22,53.29], [72.27,52.13]]
2
  • 1
    "I wanted to get something like this" - what did you get instead? Commented Jul 24, 2019 at 10:08
  • Don't forget you can upvote too :) Commented Jul 24, 2019 at 10:43

1 Answer 1

1

You can specify a size of the output array when using np.random.uniform, no need for looping:

randomReleaseAngle = np.random.uniform(20.0, 77.0, size=(5, 2))
randomVelocity = np.random.uniform(40.0, 60.0, size=(5, 2))

array([[41.34878677, 74.19071547],
       [61.72365468, 54.1235336 ],
       [28.89306251, 28.89168766],
       [23.31076589, 69.37204031],
       [54.26355567, 60.36013693]])
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.