SoFunction
Updated on 2024-10-30

Numpy and Usage and Difference Explained

(d0, d1, ..., dn) of the random sample is located in the [0, 1): this function can return one or a group of uniformly distributed ** "0 ~ 1" ** random sample values.

(d0, d1, ..., dn) is a function fromstandard normal distribution (SND)Returns one or more sample values in the

 1. ()

Grammar:

(d0,d1,d2……dn)
Note: Used in the same way as the () function

Role:
With this function you canReturns one or a group of random sample values uniformly distributed from "0 to 1".Random sample of values in the range [0,1) excluding 1

APPLICATION: In the Dropout regularization method for deep learning, which can be used to generate dropout random vectors (dl), the
For example (keep_prob indicates the proportion of neurons retained):

dl = ([0],[1]) < keep_prob

Examples:

在这里插入图片描述

Notes:

Uniform distribution.

Also called a rectangular distribution, it is a symmetric probability distribution where the probabilities of distributions at the same length interval are equally likely.

The uniform distribution is defined by two parameters a and b, which are the minimum and maximum values on the numerical axis, and is often abbreviated as U(a, b).

The probability density function of the uniform distribution is:

在这里插入图片描述

在这里插入图片描述

2. () Syntax:

(d0,d1,d2……dn)
1) When the function has no arguments inside the parentheses, it returns a floating point number;
2) When the function has a parameter inside the parentheses, it returns an array of rank 1 and cannot represent vectors or matrices;
(3) When the function has two or more parameters in parentheses, it returns an array of corresponding dimensions, capable of representing a vector or matrix;
4) The .standard_normal() function is similar to (), but the input parameter of .standard_normal() is a tuple.

# Examples:
.standard_normal((5))
# [-0.53268495 0.30171848 1.85232368 -0.58746393 0.19683992]

.standard_normal((5,2))
''' 
[[-2.44520524 2.29767001]
 [-1.19770033 -1.09569325]
 [-0.75414833 0.49509984]
 [-1.42537268 0.41788237]
 [ 1.85465491 -1.44383249]] 
 '''
 
.standard_normal((5,2,3))
'''
[[[ 0.54013502 -0.25347615 1.73395647]
 [ 1.03386947 -0.54856199 2.10004584]]

 [[-0.57632903 -0.05856844 1.72805595]
 [ 1.3507174  0.61459539 0.63380028]]

 [[-2.24857933 -1.29276097 0.42585061]
 [ 0.75974263 -0.83670586 -1.56930898]]

 [[-0.32212   1.2884624  1.53744081]
 [ 1.5444555 -1.82408734 -0.55952688]]

 [[-1.21191144 -1.40454518 -0.3369976 ]
 [-0.89314143 0.28291988 1.58394166]]]
'''

.standard_normal((5,2,3,1))
'''
[[[[ 0.19019221]
  [ 0.64618425]
  [ 0.99815722]]

 [[-0.0570328 ]
  [ 0.83271045]
  [-0.30469335]]]


 [[[-1.14788388]
  [ 0.09563431]
  [ 2.05611213]]

 [[-0.14251287]
  [ 1.00922816]
  [-0.55403104]]]


 [[[ 1.75657437]
  [ 1.46381575]
  [ 1.10527197]]

 [[ 0.22667296]
  [ 0.18305552]
  [ 0.5778761 ]]]


 [[[ 0.26501242]
  [-0.4863313 ]
  [ 1.01096974]]

 [[-2.46562874]
  [ 0.19516242]
  [-1.92500848]]]


 [[[ 0.97904566]
  [ 0.80444414]
  [ 0.99981326]]

 [[-0.74329878]
  [-0.9265738 ]
  [ 0.0288684 ]]]]
  '''

5) The input to () is usually an integer, but if it is a floating point number, it is automatically truncated and converted directly to an integer.

Role: This function allows you toReturns a random sample of values or a set of values that follow a standard normal distribution.

Characteristics: The standard normal distribution is a normal distribution with 0 as the mean and 1 as the standard deviation, denoted N(0, 1). The corresponding normal distribution curve is shown below, i.e.:

在这里插入图片描述

Notes:

The pattern of area distribution under the standard normal distribution curve is:

The area under the curve in the range -1.96 to +1.96 is equal to 0.9500 (i.e., the probability of taking a value in this range is 95%) and the area under the curve in the range -2.58 to +2.58 is 0.9900 (i.e., the probability of taking a value in this range is 99%).
Therefore, the random samples generated by the () function basically take values mainly between -1.96 and +1.96, of course, does not exclude the existence of larger values of the situation, only the probability is small.

Reference:

/abc13526222160/article/details/86423754

/BBS2013/p/

to this article on Numpy () and () Usage and the difference between the article is introduced to this, more related Numpy () and () content, please search my previous posts or continue to browse the following related articles I hope you will support me in the future!