0

what is the best way to draw samples x that have this distribution with size n? if it was uniformly

c = [0.5,0.6,0,0,0.4,0,0.2,0.2,0.1,0.1,0.1] with n = 11

in case I want to increase the noise could of use this np.random.rand(n)?

3

1 Answer 1

0

numpy.random.uniform will let you generate "n" unformly distributed samples between a given "low" and "high" limit.

For example:

import numpy as np

lower_limit = 3
upper_limit = 7
number_of_samples = 11

c = np.random.uniform(lower_limit, upper_limit, number_of_samples)

print (c)

produces:

[6.96837557 6.31203767 6.49680613 6.46568161 3.77999427 3.8421241
 6.27406087 4.60471307 4.5874396  3.7439116  4.69739617]

The range between your "lower" and "upper" limit might be regarded as a proxy for "noisiness" of the samples.

Documentation here: https://numpy.org/doc/stable/reference/random/generated/numpy.random.uniform.html

If what you're trying to do is "add noise" to a given list of values, you could generate a uniformly distributed array of random numbers to represent the "noise" and add this noise to your original list of values. For example:

noiseless_values = np.linspace(1, 10, num = 10)
noisy_values = noiseless_values * np.random.uniform(0.9, 1.1, len(noiseless_values))

for noiseless, noisy in zip(noiseless_values, noisy_values):
    print (f'{noiseless:<6}: {noisy:}')

...produces:

1.0   : 1.071975105690119
2.0   : 1.9508717288907071
3.0   : 2.8448791935778157
4.0   : 4.175151052483082
5.0   : 5.056205712396034
6.0   : 6.4584524295884735
7.0   : 6.3247828913239985
8.0   : 8.730239323071011
9.0   : 8.37164223683849
10.0  : 9.133076473380891

Hope this helps.

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

7 Comments

what about np.random.choice, because c is given ? and how to add extra noise to the data
I've just expanded my answer to describe how you might add noise to a given set of "noiseless" data. Perhaps that addresses your question?
thnks for the effort but you mean + and not * can you explain please why not consider np.random.rand as noise?
No I meant * : I'm basically multiplying each number by a randomly selected value between 0.9 and 1.1 - which will produce a value that is +/- 10% of the original value. np.random.rand(10) will produce 10 uniformly distributed random values between 0 and 1. if that's what you want, that's your answer. np.random.choice will, given an array of numbers, randomly select "n" of those values for you - it won't "add" any noise to them, or modify them in any way. If that addresses your question, great. If what you want to do is make "noiseless" data "noisy", then my suggested method should work..
thank you for your explaination :), np.random.normal(0,1,100) also considered noise added to noiseless data, right ?
|

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.