Class NumPyRandom
- Namespace
- NumSharp
- Assembly
- NumSharp.dll
A class that serves as numpy.random.RandomState in python.
public class NumPyRandom
- Inheritance
-
NumPyRandom
- Inherited Members
- Extension Methods
Remarks
Constructors
NumPyRandom()
protected NumPyRandom()
NumPyRandom(NativeRandomState)
protected NumPyRandom(NativeRandomState nativeRandomState)
Parameters
nativeRandomStateNativeRandomState
NumPyRandom(Randomizer)
protected NumPyRandom(Randomizer randomizer)
Parameters
randomizerRandomizer
NumPyRandom(int)
protected NumPyRandom(int seed)
Parameters
seedint
Fields
randomizer
protected Randomizer randomizer
Field Value
Properties
Seed
public int Seed { get; set; }
Property Value
Methods
RandomState()
Returns a new instance of NumPyRandom.
public NumPyRandom RandomState()
Returns
RandomState(NativeRandomState)
Returns a new instance of NumPyRandom.
public NumPyRandom RandomState(NativeRandomState state)
Parameters
stateNativeRandomState
Returns
RandomState(int)
Returns a new instance of NumPyRandom.
public NumPyRandom RandomState(int seed)
Parameters
seedint
Returns
bernoulli(double, Shape)
Draw samples from a bernoulli distribution.
public NDArray bernoulli(double p, Shape shape)
Parameters
Returns
- NDArray
Drawn samples from the parameterized bernoulli distribution.
bernoulli(double, params int[])
Draw samples from a bernoulli distribution.
public NDArray bernoulli(double p, params int[] dims)
Parameters
Returns
- NDArray
Drawn samples from the parameterized bernoulli distribution.
beta(double, double, Shape)
Draw samples from a Beta distribution. The Beta distribution is a special case of the Dirichlet distribution, and is related to the Gamma distribution.It has the probability distribution function
public NDArray beta(double alpha, double betaValue, Shape shape)
Parameters
Returns
beta(double, double, params int[])
Draw samples from a Beta distribution. The Beta distribution is a special case of the Dirichlet distribution, and is related to the Gamma distribution.It has the probability distribution function
public NDArray beta(double alpha, double betaValue, params int[] dims)
Parameters
Returns
binomial(int, double, Shape)
Draw samples from a binomial distribution. Samples are drawn from a binomial distribution with specified parameters, n trials and p probability of success where n an integer >= 0 and p is in the interval[0, 1]. (n may be input as a float, but it is truncated to an integer in use)
public NDArray binomial(int n, double p, Shape shape)
Parameters
nintParameter of the distribution, >= 0. Floats are also accepted, but they will be truncated to integers.
pdoubleParameter of the distribution, >= 0 and <=1.
shapeShapeOutput Shape
Returns
- NDArray
Drawn samples from the parameterized binomial distribution, where each sample is equal to the number of successes over the n trials.
Remarks
binomial(int, double, params int[])
Draw samples from a binomial distribution. Samples are drawn from a binomial distribution with specified parameters, n trials and p probability of success where n an integer >= 0 and p is in the interval[0, 1]. (n may be input as a float, but it is truncated to an integer in use)
public NDArray binomial(int n, double p, params int[] dims)
Parameters
nintParameter of the distribution, >= 0. Floats are also accepted, but they will be truncated to integers.
pdoubleParameter of the distribution, >= 0 and <=1.
dimsint[]Output Shape
Returns
- NDArray
Drawn samples from the parameterized binomial distribution, where each sample is equal to the number of successes over the n trials.
Remarks
chisquare(double, Shape)
Draw samples from a chi-square distribution. When df independent random variables, each with standard normal distributions(mean 0, variance 1), are squared and summed, the resulting distribution is chi-square(see Notes). This distribution is often used in hypothesis testing.
public NDArray chisquare(double df, Shape shape)
Parameters
Returns
- NDArray
Drawn samples from the parameterized chi-square distribution.
Remarks
chisquare(double, params int[])
Draw samples from a chi-square distribution. When df independent random variables, each with standard normal distributions(mean 0, variance 1), are squared and summed, the resulting distribution is chi-square(see Notes). This distribution is often used in hypothesis testing.
public NDArray chisquare(double df, params int[] dims)
Parameters
Returns
- NDArray
Drawn samples from the parameterized chi-square distribution.
Remarks
choice(NDArray, Shape, bool, double[])
Generates a random sample from a given 1-D array
public NDArray choice(NDArray arr, Shape shape = default, bool replace = true, double[] probabilities = null)
Parameters
arrNDArrayIf an ndarray, a random sample is generated from its elements. If an int, the random sample is generated as if a were np.arange(a)
shapeShapeOutput shape. If the given shape is, e.g., (m, n, k), then m * n * k samples are drawn. Default is None, in which case a single value is returned.
replaceboolWhether the sample is with or without replacement
probabilitiesdouble[]The probabilities associated with each entry in a. If not given the sample assumes a uniform distribution over all entries in a.
Returns
Remarks
choice(int, Shape, bool, double[])
Generates a random sample from a given 1-D array
public NDArray choice(int a, Shape shape = default, bool replace = true, double[] probabilities = null)
Parameters
aintIf an ndarray, a random sample is generated from its elements. If an int, the random sample is generated as if a were np.arange(a)
shapeShapeOutput shape. If the given shape is, e.g., (m, n, k), then m * n * k samples are drawn. Default is None, in which case a single value is returned.
replaceboolWhether the sample is with or without replacement
probabilitiesdouble[]The probabilities associated with each entry in a. If not given the sample assumes a uniform distribution over all entries in a.
Returns
Remarks
exponential(double, Shape)
Draw samples from an exponential distribution. The exponential distribution is a continuous analogue of the geometric distribution. It describes many common situations, such as the size of raindrops measured over many rainstorms
public NDArray exponential(double scale, Shape shape)
Parameters
Returns
- NDArray
Drawn samples from the parameterized exponential distribution.
Remarks
exponential(double, params int[])
Draw samples from an exponential distribution. The exponential distribution is a continuous analogue of the geometric distribution. It describes many common situations, such as the size of raindrops measured over many rainstorms
public NDArray exponential(double scale, params int[] dims)
Parameters
Returns
- NDArray
Drawn samples from the parameterized exponential distribution.
Remarks
gamma(double, double, Shape)
Draw samples from a Gamma distribution. Samples are drawn from a Gamma distribution with specified parameters, shape (sometimes designated “k”) and scale(sometimes designated “theta”), where both parameters are > 0.
public NDArray gamma(double shapeV, double scale, Shape shape)
Parameters
shapeVdoubleThe shape of the gamma distribution. Should be greater than zero.
scaledoubleThe scale of the gamma distribution. Should be greater than zero. Default is equal to 1.
shapeShapeOutput shape.
Returns
- NDArray
Drawn samples from the parameterized gamma distribution.
Remarks
gamma(double, double, params int[])
Draw samples from a Gamma distribution. Samples are drawn from a Gamma distribution with specified parameters, shape (sometimes designated “k”) and scale(sometimes designated “theta”), where both parameters are > 0.
public NDArray gamma(double shape, double scale, params int[] dims)
Parameters
shapedoubleThe shape of the gamma distribution. Should be greater than zero.
scaledoubleThe scale of the gamma distribution. Should be greater than zero. Default is equal to 1.
dimsint[]Output shape.
Returns
- NDArray
Drawn samples from the parameterized gamma distribution.
Remarks
geometric(double, Shape)
Draw samples from the geometric distribution. Bernoulli trials are experiments with one of two outcomes: success or failure(an example of such an experiment is flipping a coin). The geometric distribution models the number of trials that must be run in order to achieve success.It is therefore supported on the positive integers, k = 1, 2, ....
public NDArray geometric(double p, Shape shape)
Parameters
Returns
- NDArray
Drawn samples from the parameterized geometric distribution.
Remarks
geometric(double, params int[])
Draw samples from the geometric distribution. Bernoulli trials are experiments with one of two outcomes: success or failure(an example of such an experiment is flipping a coin). The geometric distribution models the number of trials that must be run in order to achieve success.It is therefore supported on the positive integers, k = 1, 2, ....
public NDArray geometric(double p, params int[] dims)
Parameters
Returns
- NDArray
Drawn samples from the parameterized geometric distribution.
Remarks
get_state()
Return a NumPyRandom representing the internal state of the generator.
public NativeRandomState get_state()
Returns
lognormal(double, double, Shape)
Draw samples from a log-normal distribution. Draw samples from a log-normal distribution with specified mean, standard deviation, and array shape. Note that the mean and standard deviation are not the values for the distribution itself, but of the underlying normal distribution it is derived from.
public NDArray lognormal(double mean, double sigma, Shape shape)
Parameters
meandoubleMean value of the underlying normal distribution. Default is 0.
sigmadoubleStandard deviation of the underlying normal distribution. Should be greater than zero. Default is 1.
shapeShapeOutput Shape
Returns
- NDArray
Drawn samples from the parameterized bernoulli distribution.
Remarks
lognormal(double, double, params int[])
Draw samples from a log-normal distribution. Draw samples from a log-normal distribution with specified mean, standard deviation, and array shape. Note that the mean and standard deviation are not the values for the distribution itself, but of the underlying normal distribution it is derived from.
public NDArray lognormal(double mean, double sigma, params int[] dims)
Parameters
meandoubleMean value of the underlying normal distribution. Default is 0.
sigmadoubleStandard deviation of the underlying normal distribution. Should be greater than zero. Default is 1.
dimsint[]Output Shape
Returns
- NDArray
Drawn samples from the parameterized bernoulli distribution.
Remarks
normal(double, double, params int[])
Draw random samples from a normal (Gaussian) distribution.
public NDArray normal(double loc, double scale, params int[] dims)
Parameters
Returns
permutation(NDArray)
Randomly permute a sequence, or return a permuted range.
public NDArray permutation(NDArray x)
Parameters
xNDArrayIf x is an integer, randomly permute np.arange(x).
Returns
- NDArray
Permuted sequence or array range.
Remarks
permutation(int)
Randomly permute a sequence, or return a permuted range.
public NDArray permutation(int x)
Parameters
xintIf x is an integer, randomly permute np.arange(x).
Returns
- NDArray
Permuted sequence or array range.
Remarks
poisson(double, Shape)
Draw samples from a Poisson distribution. The Poisson distribution is the limit of the binomial distribution for large N.
public NDArray poisson(double lam, Shape shape)
Parameters
lamdoubleExpectation of interval, should be >= 0. A sequence of expectation intervals must be broadcastable over the requested size.
shapeShapeOutput Shape
Returns
- NDArray
Drawn samples from the parameterized binomial distribution, where each sample is equal to the number of successes over the n trials.
Remarks
poisson(double, params int[])
Draw samples from a Poisson distribution. The Poisson distribution is the limit of the binomial distribution for large N.
public NDArray poisson(double lam, params int[] dims)
Parameters
lamdoubleExpectation of interval, should be >= 0. A sequence of expectation intervals must be broadcastable over the requested size.
dimsint[]Output Shape
Returns
- NDArray
Drawn samples from the parameterized binomial distribution, where each sample is equal to the number of successes over the n trials.
Remarks
rand(Shape)
Random values in a given shape. Create an array of the given shape and populate it with random samples from a uniform distribution over [0, 1).
public NDArray rand(Shape shape)
Parameters
shapeShape
Returns
rand(params int[])
Random values in a given shape. Create an array of the given shape and populate it with random samples from a uniform distribution over [0, 1).
public NDArray rand(params int[] size)
Parameters
sizeint[]
Returns
randint(long, long, Shape, Type)
Return random integers from the “discrete uniform” distribution of the specified dtype in the “half-open” interval [low, high). If high is None (the default), then results are from [0, low).
public NDArray randint(long low, long high = -1, Shape size = default, Type dtype = null)
Parameters
lowlongLowest (signed) integer to be drawn from the distribution (unless high=-1, in which case this parameter is one above the highest such integer).
highlongIf provided, one above the largest (signed) integer to be drawn from the distribution (see above for behavior if high=-1).
sizeShapeThe shape of the array.
dtypeTypeDesired dtype of the result. All dtypes are determined by their name, i.e., ‘int64’, ‘int’, etc, so byteorder is not available and a specific precision may have different C types depending on the platform. The default value is ‘np.int’.
Returns
Remarks
randn(params int[])
Return a sample (or samples) from the “standard normal” distribution.
public NDArray randn(params int[] size)
Parameters
sizeint[]
Returns
randn<T>()
Scalar value
public T randn<T>()
Returns
- T
Type Parameters
T
random_sample(Shape)
Return random floats in the half-open interval [0.0, 1.0). Results are from the “continuous uniform” distribution over the stated interval. To sample Unif[a, b), b > a multiply the output of random_sample by (b-a) and add a:
public NDArray random_sample(Shape shape)
Parameters
shapeShapeThe shape to randomize
Returns
random_sample(params int[])
Return random floats in the half-open interval [0.0, 1.0). Results are from the “continuous uniform” distribution over the stated interval. To sample Unif[a, b), b > a multiply the output of random_sample by (b-a) and add a:
public NDArray random_sample(params int[] size)
Parameters
sizeint[]The samples
Returns
seed(int)
Seeds the generator. It can be called again to re-seed the generator.
public void seed(int seed)
Parameters
seedint
set_state(NativeRandomState)
Set the internal state of the generator from a NumPyRandom. for use if one has reason to manually (re-)set the internal state of the pseudo-random number generating algorithm.
public void set_state(NativeRandomState nativeRandomState)
Parameters
nativeRandomStateNativeRandomStateThe state to restore onto this NumPyRandom
shuffle(NDArray, int)
Modify a sequence in-place by shuffling its contents.
[SuppressMessage("ReSharper", "TooWideLocalVariableScope")]
public void shuffle(NDArray x, int passes = 2)
Parameters
xNDArrayThe array or list to be shuffled.
passesintHow many times to pass all items in a complexity of O(n*passes)
Remarks
stardard_normal(params int[])
Draw samples from a standard Normal distribution (mean=0, stdev=1).
public NDArray stardard_normal(params int[] size)
Parameters
sizeint[]
Returns
uniform(NDArray, NDArray, Type)
Draw samples from a uniform distribution. Samples are uniformly distributed over the half-open interval [low, high) (includes low, but excludes high). In other words, any value within the given interval is equally likely to be drawn by uniform.
public NDArray uniform(NDArray low, NDArray high, Type dType = null)
Parameters
lowNDArrayLower boundary of the output interval. All values generated will be greater than or equal to low. The default value is 0.
highNDArrayUpper boundary of the output interval. All values generated will be less than high. The default value is 1.0.
dTypeTypeThe type of the output NDArray
Returns
uniform(double, double, Shape)
Draw samples from a uniform distribution. Samples are uniformly distributed over the half-open interval [low, high) (includes low, but excludes high). In other words, any value within the given interval is equally likely to be drawn by uniform.
public NDArray uniform(double low, double high, Shape shape)
Parameters
lowdoubleLower boundary of the output interval. All values generated will be greater than or equal to low. The default value is 0.
highdoubleUpper boundary of the output interval. All values generated will be less than high. The default value is 1.0.
shapeShapeOutput shape. If the given shape is, e.g., m, n, k, then m * n * k samples are drawn. If size is None (default), a single value is returned if low and high are both scalars.
Returns
uniform(double, double, params int[])
Draw samples from a uniform distribution. Samples are uniformly distributed over the half-open interval [low, high) (includes low, but excludes high). In other words, any value within the given interval is equally likely to be drawn by uniform.
public NDArray uniform(double low, double high, params int[] size)
Parameters
lowdoubleLower boundary of the output interval. All values generated will be greater than or equal to low. The default value is 0.
highdoubleUpper boundary of the output interval. All values generated will be less than high. The default value is 1.0.
sizeint[]Output shape. If the given shape is, e.g., m, n, k, then m * n * k samples are drawn. If size is None (default), a single value is returned if low and high are both scalars.