Python Forum
random.seed and random.randn
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
random.seed and random.randn
#2
Concerning randn(), your output has length 100, so that there is no issue.

Concerning seed(), the purpose of such functions is to generate repeatable pseudo random sequences, for example
>>> np.random.seed(42)
>>> np.random.randn(5)
array([ 0.49671415, -0.1382643 ,  0.64768854,  1.52302986, -0.23415337])
>>> np.random.seed(42) # restart the generator with the same seed
>>> np.random.randn(5)
array([ 0.49671415, -0.1382643 ,  0.64768854,  1.52302986, -0.23415337]) # same random sequence
>>> np.random.seed(3748867) # a different seed
>>> np.random.randn(5)
array([-1.87666266,  2.5862967 , -0.49532264, -0.01653639,  0.01915029]) # a different random sequence
>>> 
That said, numpy's documentation describes seed() as a convenience, legacy function. It means that one shouldn't call it but probably use RandomState instances instead, which also have seed() and randn() methods (be cautious however as RandomState is also described as a legacy class in other parts of the documentation, seeding seems to be a tricky subject. As an average user, one can perhaps avoid the details).
Reply


Messages In This Thread
random.seed and random.randn - by Truman - May-28-2020, 09:09 PM
RE: random.seed and random.randn - by Gribouillis - May-29-2020, 05:51 AM
RE: random.seed and random.randn - by Truman - May-29-2020, 07:48 PM
RE: random.seed and random.randn - by Gribouillis - May-29-2020, 09:06 PM
RE: random.seed and random.randn - by Truman - May-29-2020, 09:49 PM
RE: random.seed and random.randn - by Truman - May-30-2020, 08:59 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Random Forest to Identify Page: Feature Selection JaneTan 0 1,384 Oct-14-2021, 09:40 AM
Last Post: JaneTan
  How can I know the value of a field at a random point? player1682 0 1,204 Oct-12-2021, 02:16 PM
Last Post: player1682
  Random Particle Simulation in Blender willm168 3 2,851 Jul-13-2021, 10:54 AM
Last Post: Larz60+
  Can't make Random Forest Prediction work donnertrud 0 1,714 May-23-2020, 12:26 PM
Last Post: donnertrud
  Breaking a loop in Multiple Random Walks PythonGainz 10 4,392 May-01-2020, 03:15 PM
Last Post: buran
  Random Forest Hyperparamter Optimization donnertrud 1 2,028 Jan-17-2020, 06:30 AM
Last Post: scidam
  Random Forest high R2 Score but poor prediction donnertrud 5 5,322 Jan-13-2020, 11:23 PM
Last Post: jefsummers
  How to create a random library for an specific function andre_fermart 4 3,451 Apr-10-2019, 11:02 PM
Last Post: andre_fermart
  fill an empty matrix with random floats sofiapuvogel 2 3,356 Oct-29-2018, 12:33 PM
Last Post: ichabod801
  Removing rows at random based on the value of a specific column Mr_Keystrokes 4 5,806 Aug-24-2018, 11:15 AM
Last Post: Mr_Keystrokes

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020