np.random.seed的作用

为了复现实验,相同的seed值可以保证随机序列一致

测试程序:

import numpy as np
np.random.seed(5)
A=np.random.randn(5,4,3)
print(A)
np.random.seed(6)
B=np.random.randn(5,4,3)
print(B)
np.random.seed(5)
C=np.random.randn(5,4,3)
print(C)
np.random.seed(6)
D=np.random.randn(5,4,3)
print(D)

测试结果:

[[[ 0.44122749 -0.33087015  2.43077119]
  [-0.25209213  0.10960984  1.58248112]
  [-0.9092324  -0.59163666  0.18760323]
  [-0.32986996 -1.19276461 -0.20487651]]

 [[-0.35882895  0.6034716  -1.66478853]
  [-0.70017904  1.15139101  1.85733101]
  [-1.51117956  0.64484751 -0.98060789]
  [-0.85685315 -0.87187918 -0.42250793]]

 [[ 0.99643983  0.71242127  0.05914424]
  [-0.36331088  0.00328884 -0.10593044]
  [ 0.79305332 -0.63157163 -0.00619491]
  [-0.10106761 -0.05230815  0.24921766]]

 [[ 0.19766009  1.33484857 -0.08687561]
  [ 1.56153229 -0.30585302 -0.47773142]
  [ 0.10073819  0.35543847  0.26961241]
  [ 1.29196338  1.13934298  0.4944404 ]]

 [[-0.33633626 -0.10061435  1.41339802]
  [ 0.22125412 -1.31077313 -0.68956523]
  [-0.57751323  1.15220477 -0.10716398]
  [ 2.26010677  0.65661947  0.12480683]]] (5, 4, 3)
[[[-0.31178367  0.72900392  0.21782079]
  [-0.8990918  -2.48678065  0.91325152]
  [ 1.12706373 -1.51409323  1.63929108]
  [-0.4298936   2.63128056  0.60182225]]

 [[-0.33588161  1.23773784  0.11112817]
  [ 0.12915125  0.07612761 -0.15512816]
  [ 0.63422534  0.810655    0.35480861]
  [ 1.81259031 -1.3564758  -0.46363197]]

 [[ 0.82465384 -1.17643148  1.56448966]
  [ 0.71270509 -0.1810066   0.53419953]
  [-0.58661296 -1.48185327  0.85724762]
  [ 0.94309899  0.11444143 -0.02195668]]

 [[-2.12714455 -0.83440747 -0.46550831]
  [ 0.23371059  1.38503523 -0.51962709]
  [-0.78015214  0.95560959 -0.12673638]
  [-1.36861282  1.21848065 -0.85750144]]

 [[-0.56147088 -1.0335199   0.35877096]
  [ 1.07368134 -0.37550472  0.39636757]
  [-0.47144628  2.33660781  1.50278553]
  [-0.59545972  0.52834106  0.9398248 ]]] (5, 4, 3)
[[[ 0.44122749 -0.33087015  2.43077119]
  [-0.25209213  0.10960984  1.58248112]
  [-0.9092324  -0.59163666  0.18760323]
  [-0.32986996 -1.19276461 -0.20487651]]

 [[-0.35882895  0.6034716  -1.66478853]
  [-0.70017904  1.15139101  1.85733101]
  [-1.51117956  0.64484751 -0.98060789]
  [-0.85685315 -0.87187918 -0.42250793]]

 [[ 0.99643983  0.71242127  0.05914424]
  [-0.36331088  0.00328884 -0.10593044]
  [ 0.79305332 -0.63157163 -0.00619491]
  [-0.10106761 -0.05230815  0.24921766]]

 [[ 0.19766009  1.33484857 -0.08687561]
  [ 1.56153229 -0.30585302 -0.47773142]
  [ 0.10073819  0.35543847  0.26961241]
  [ 1.29196338  1.13934298  0.4944404 ]]

 [[-0.33633626 -0.10061435  1.41339802]
  [ 0.22125412 -1.31077313 -0.68956523]
  [-0.57751323  1.15220477 -0.10716398]
  [ 2.26010677  0.65661947  0.12480683]]] (5, 4, 3)
[[[-0.31178367  0.72900392  0.21782079]
  [-0.8990918  -2.48678065  0.91325152]
  [ 1.12706373 -1.51409323  1.63929108]
  [-0.4298936   2.63128056  0.60182225]]

 [[-0.33588161  1.23773784  0.11112817]
  [ 0.12915125  0.07612761 -0.15512816]
  [ 0.63422534  0.810655    0.35480861]
  [ 1.81259031 -1.3564758  -0.46363197]]

 [[ 0.82465384 -1.17643148  1.56448966]
  [ 0.71270509 -0.1810066   0.53419953]
  [-0.58661296 -1.48185327  0.85724762]
  [ 0.94309899  0.11444143 -0.02195668]]

 [[-2.12714455 -0.83440747 -0.46550831]
  [ 0.23371059  1.38503523 -0.51962709]
  [-0.78015214  0.95560959 -0.12673638]
  [-1.36861282  1.21848065 -0.85750144]]

 [[-0.56147088 -1.0335199   0.35877096]
  [ 1.07368134 -0.37550472  0.39636757]
  [-0.47144628  2.33660781  1.50278553]
  [-0.59545972  0.52834106  0.9398248 ]]] (5, 4, 3)

Process finished with exit code 0

 

你可能感兴趣的:(python基础)