SoFunction
Updated on 2024-10-30

python artificial intelligence tensorflow function module use

Introduction to some of the methods commonly used by the module

name (of a thing) corresponds English -ity, -ism, -ization
(d0, d1, …, dn) Generates a [d0, d1, ..., dn]-dimensional numpy array with elements taken from the mean distribution on [0, 1), or, if there is no parameter input, a number of [0, 1).
(d0, d1, …, dn) Generate a [d0, d1, ..., dn]-dimensional numpy array with a standard normal distribution.
(low, high=None, size=None, dtype=‘I’) Generates an integer in the range [low, high) or in the interval [0, low) if the parameter high is not entered.
(low=0.0, high=1.0, size=None) Generates a floating-point number that conforms to a uniform distribution with values in the range [low, high) and a default value in the range [0, 1.0).
(loc=0.0, scale=1.0, size=None) Generate floating point numbers with mean loc, standard deviation scale, and shape size according to a normal distribution.
(size=None) Generates a floating point number between [0.0, 1.0).
(a, size=None, replace=True, p=None) A random number of size (dimension) size is selected from a (array), replace=True means repeatable extraction, and p is the probability that each number in a occurs. If a is an integer, the array represented by a is array(a).

(for) instance

(d0, d1, …, dn):

Generates a [d0, d1, ..., dn]-dimensional numpy array with elements taken from the mean distribution on [0, 1), or, if there is no parameter input, a number of [0, 1).

import numpy as np
v1 = ()
v2 = (3,4)
print(v1)
print(v2)

The output result is:

0.618411110932038
[[0.35134062 0.55609186 0.4173297  0.85541691]
 [0.35144304 0.31204156 0.60196109 0.390464  ]
 [0.19186067 0.94570486 0.8637441  0.07028114]]

(d0, d1, …, dn):

Generate a [d0, d1, ..., dn]-dimensional numpy array with a standard normal distribution.

import numpy as np
v1 = ()
v2 = (3,4)
print(v1)
print(v2)

The output result is:

0.47263651836701953
[[-0.23431214  0.97197099  0.52845269 -0.45246824]
 [-1.1266395  -1.60040653 -2.64602615 -0.19457032]
 [-0.520287   -1.0799122   0.08441667  0.34980224]]

(low, high=None, size=None, dtype=‘I’):

Generates an integer in the range [low, high) or in the interval [0, low) if the parameter high is not entered.

import numpy as np
v1 = (5)
v2 = (1,high = 5)
v3 = (1,high = 5,size = [3,4])
print(v1)
print(v2)
print(v3)

The output result is:

2
3
[[1 1 3 1]
 [2 2 3 2]
 [3 4 2 1]]

(low=0.0, high=1.0, size=None):

Generates a floating-point number that conforms to a uniform distribution with values in the range [low, high) and a default value in the range [0, 1.0).

import numpy as np
v1 = ()
v2 = (low = 0,high = 5)
v3 = (low = 0,high = 5,size = [3,4])
print(v1)
print(v2)
print(v3)

The output result is:

0.6925621763952164
3.0483936610544218
[[1.34959297 4.84117424 0.41277118 4.81392216]
 [2.91266734 0.87922181 3.39729422 3.34340092]
 [0.45158364 3.8129479  0.54246798 2.57192192]]

(loc=0.0, scale=1.0, size=None)

Generate floating point numbers with mean loc, standard deviation scale, and shape size according to a normal distribution.

import numpy as np
v1 = ()
v2 = (loc = 0,scale = 5)
v3 = (loc = 0,scale = 5,size = [3,4])
print(v1)
print(v2)
print(v3)

The output result is:

0.7559391954091367
-3.359831771004067
[[  3.90821047   6.37757533   6.3813528    0.86219281]
 [ -3.61201084   4.05948053  -3.91172941  11.29050165]
 [ -8.60318633 -10.07090496  -4.86557867   7.98536182]]

(size=None)

Generates a floating point number between [0.0, 1.0).

import numpy as np
v1 = ()
v2 = (size = [3,4])
print(v1)
print(v2)

The output result is:

0.5930924941107145
[[0.41002067 0.28097163 0.8908558  0.16951515]
 [0.59730596 0.57475303 0.84174255 0.59633522]
 [0.63508879 0.44138737 0.6223043  0.61540997]]

(a, size=None, replace=True, p=None)

Random numbers of size (dimension) size are selected from a (array), replace=True means repeatable extraction, and p is the probability that each number in a occurs.

If a is an integer, the array represented by a is range(a).

import numpy as np
v1 = (5)
v2 = (5,size = 5)
v3 = ([1,2,3,4,5],size = 5)
v4 = ([1,2,3,4,5],size = 5,p = [1,0,0,0,0])
v5 = ([1,2,3,4,5],size = 5,replace = False)
print("v1:",v1)
print("v2:",v2)
print("v3:",v3)
print("v4:",v4)
print("v5:",v5)

The output result is:

v1: 1
v2: [0 0 4 0 4]
v3: [3 2 3 1 1]
v4: [1 1 1 1 1]
v5: [4 2 3 5 1]

Above is the detailed content of python artificial intelligence tensorflow function module usage, more information about tensorflow function module please pay attention to my other related articles!