0

I have created a list containing 10 arrays that consist of 20 random numbers between 0 and 1 each.

Now, I wish to multiply each array in the list with the numbers 0.05, 0.1, ..., to 1.0 so that none of the elements in each array is larger than the number it is multiplied with.

For example, all the 20 elements in the first array should lie between 0 and 0.05, all the elements in the second array between 0 and 0.10 and so on.

I create a list of 10 random arrays and a range of numbers between 0 and 1 with:

range1 = np.arange(0.005, 0.105, 0.005)
noise1 = [abs(np.random.uniform(0,1,20)) for i in range(10)]

I then try to multiply the elements with:

noise2 = [noise1 * range1 for i in noise1]

But this doesn't work and just causes all the arrays in the list to have the same values.

I would really appreciate some help with how to do this.

3
  • Have you tried just normalizing the values to be within the range for 0 to 0.05, etc. ? x' = 0 + ((x - xmin)(0.05 - 0))/(xmax - xmin) Commented Mar 15, 2018 at 16:28
  • Why are you making a list of arrays instead of one big array? Also, you should use linspace instead of arange for floating-point values. Commented Mar 15, 2018 at 16:28
  • 1
    And did you notice you're not using i? Commented Mar 15, 2018 at 16:29

2 Answers 2

1

Hoping I have clearly understood the question and hence providing this solution.

noise2 = [noise1[i] * range1[i] for i in range(len(noise1))]

Sign up to request clarification or add additional context in comments.

Comments

0

A more pythonic way would be using zip:

range1 = [1, 2, 3]
noise1 = [3, 4, 5]
noise2 = [i * j for i, j in zip(range1, noise1)]
# [3, 8, 15]

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.