Table of Contents

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

nativeRandomState NativeRandomState

NumPyRandom(Randomizer)

protected NumPyRandom(Randomizer randomizer)

Parameters

randomizer Randomizer

NumPyRandom(int)

protected NumPyRandom(int seed)

Parameters

seed int

Fields

randomizer

protected Randomizer randomizer

Field Value

Randomizer

Properties

Seed

public int Seed { get; set; }

Property Value

int

Methods

RandomState()

Returns a new instance of NumPyRandom.

public NumPyRandom RandomState()

Returns

NumPyRandom

RandomState(NativeRandomState)

Returns a new instance of NumPyRandom.

public NumPyRandom RandomState(NativeRandomState state)

Parameters

state NativeRandomState

Returns

NumPyRandom

RandomState(int)

Returns a new instance of NumPyRandom.

public NumPyRandom RandomState(int seed)

Parameters

seed int

Returns

NumPyRandom

bernoulli(double, Shape)

Draw samples from a bernoulli distribution.

public NDArray bernoulli(double p, Shape shape)

Parameters

p double

Parameter of the distribution, >= 0 and <=1.

shape Shape

Output Shape

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

p double

Parameter of the distribution, >= 0 and <=1.

dims int[]

Output Shape

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

alpha double

Alpha value

betaValue double

Beta value

shape Shape

Output Shape

Returns

NDArray

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

alpha double

Alpha value

betaValue double

Beta value

dims int[]

Output Shape

Returns

NDArray

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

n int

Parameter of the distribution, >= 0. Floats are also accepted, but they will be truncated to integers.

p double

Parameter of the distribution, >= 0 and <=1.

shape Shape

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

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

n int

Parameter of the distribution, >= 0. Floats are also accepted, but they will be truncated to integers.

p double

Parameter of the distribution, >= 0 and <=1.

dims int[]

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

df double

Number of degrees of freedom, should be > 0.

shape Shape

Output Shape

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

df double

Number of degrees of freedom, should be > 0.

dims int[]

Output Shape

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

arr NDArray

If 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)

shape Shape

Output 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.

replace bool

Whether the sample is with or without replacement

probabilities double[]

The probabilities associated with each entry in a. If not given the sample assumes a uniform distribution over all entries in a.

Returns

NDArray

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

a int

If 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)

shape Shape

Output 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.

replace bool

Whether the sample is with or without replacement

probabilities double[]

The probabilities associated with each entry in a. If not given the sample assumes a uniform distribution over all entries in a.

Returns

NDArray

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

scale double

The scale parameter, \beta = 1/\lambda.

shape Shape

Output Shape

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

scale double

The scale parameter, \beta = 1/\lambda.

dims int[]

Output Shape

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

shapeV double

The shape of the gamma distribution. Should be greater than zero.

scale double

The scale of the gamma distribution. Should be greater than zero. Default is equal to 1.

shape Shape

Output 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

shape double

The shape of the gamma distribution. Should be greater than zero.

scale double

The scale of the gamma distribution. Should be greater than zero. Default is equal to 1.

dims int[]

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

p double

The probability of success of an individual trial.

shape Shape

Output Shape

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

p double

The probability of success of an individual trial.

dims int[]

Output Shape

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

NativeRandomState

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

mean double

Mean value of the underlying normal distribution. Default is 0.

sigma double

Standard deviation of the underlying normal distribution. Should be greater than zero. Default is 1.

shape Shape

Output 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

mean double

Mean value of the underlying normal distribution. Default is 0.

sigma double

Standard deviation of the underlying normal distribution. Should be greater than zero. Default is 1.

dims int[]

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

loc double

Mean of the distribution

scale double

Standard deviation of the distribution

dims int[]

Returns

NDArray

permutation(NDArray)

Randomly permute a sequence, or return a permuted range.

public NDArray permutation(NDArray x)

Parameters

x NDArray

If 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

x int

If 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

lam double

Expectation of interval, should be >= 0. A sequence of expectation intervals must be broadcastable over the requested size.

shape Shape

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

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

lam double

Expectation of interval, should be >= 0. A sequence of expectation intervals must be broadcastable over the requested size.

dims int[]

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

shape Shape

Returns

NDArray

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

size int[]

Returns

NDArray

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

low long

Lowest (signed) integer to be drawn from the distribution (unless high=-1, in which case this parameter is one above the highest such integer).

high long

If provided, one above the largest (signed) integer to be drawn from the distribution (see above for behavior if high=-1).

size Shape

The shape of the array.

dtype Type

Desired 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

NDArray

Remarks

randn(params int[])

Return a sample (or samples) from the “standard normal” distribution.

public NDArray randn(params int[] size)

Parameters

size int[]

Returns

NDArray

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

shape Shape

The shape to randomize

Returns

NDArray

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

size int[]

The samples

Returns

NDArray

seed(int)

Seeds the generator. It can be called again to re-seed the generator.

public void seed(int seed)

Parameters

seed int

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

nativeRandomState NativeRandomState

The 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

x NDArray

The array or list to be shuffled.

passes int

How 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

size int[]

Returns

NDArray

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

low NDArray

Lower boundary of the output interval. All values generated will be greater than or equal to low. The default value is 0.

high NDArray

Upper boundary of the output interval. All values generated will be less than high. The default value is 1.0.

dType Type

The type of the output NDArray

Returns

NDArray

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

low double

Lower boundary of the output interval. All values generated will be greater than or equal to low. The default value is 0.

high double

Upper boundary of the output interval. All values generated will be less than high. The default value is 1.0.

shape Shape

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.

Returns

NDArray

NDArray with values of type double

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

low double

Lower boundary of the output interval. All values generated will be greater than or equal to low. The default value is 0.

high double

Upper boundary of the output interval. All values generated will be less than high. The default value is 1.0.

size int[]

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.

Returns

NDArray

NDArray with values of type double