Python Forum
random.seed and random.randn
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
random.seed and random.randn
#3
(May-29-2020, 05:51 AM)Gribouillis Wrote: Concerning randn(), your output has length 100, so that there is no issue.
Yes, now I see that you're right. I must've been drunk while counting it the last night.

(May-29-2020, 05:51 AM)Gribouillis Wrote: 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).
I understand seed() method from the beginning but don't see why 42 is in parenthesis. Could it be any other number? In documentation, we have 0.
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,388 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,206 Oct-12-2021, 02:16 PM
Last Post: player1682
  Random Particle Simulation in Blender willm168 3 2,864 Jul-13-2021, 10:54 AM
Last Post: Larz60+
  Can't make Random Forest Prediction work donnertrud 0 1,725 May-23-2020, 12:26 PM
Last Post: donnertrud
  Breaking a loop in Multiple Random Walks PythonGainz 10 4,400 May-01-2020, 03:15 PM
Last Post: buran
  Random Forest Hyperparamter Optimization donnertrud 1 2,038 Jan-17-2020, 06:30 AM
Last Post: scidam
  Random Forest high R2 Score but poor prediction donnertrud 5 5,362 Jan-13-2020, 11:23 PM
Last Post: jefsummers
  How to create a random library for an specific function andre_fermart 4 3,471 Apr-10-2019, 11:02 PM
Last Post: andre_fermart
  fill an empty matrix with random floats sofiapuvogel 2 3,367 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,822 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