Python Forum
random.seed and random.randn
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
random.seed and random.randn
#1
import numpy as np 
np.random.seed(42)
x = np.random.randn(100)
I have a problem with understanding this simple code. Firstly, why 42 in parenthesis? Zero there would mean that the whole array is going to be remembered as it is. What's the difference with the other number inside?
regarding randn it gives standard normal distribution but I don't understand why does it give more numbers than 100. What 100 represents?

output:
Output:
[ 0.49671415 -0.1382643 0.64768854 1.52302986 -0.23415337 -0.23413696 1.57921282 0.76743473 -0.46947439 0.54256004 -0.46341769 -0.46572975 0.24196227 -1.91328024 -1.72491783 -0.56228753 -1.01283112 0.31424733 -0.90802408 -1.4123037 1.46564877 -0.2257763 0.0675282 -1.42474819 -0.54438272 0.11092259 -1.15099358 0.37569802 -0.60063869 -0.29169375 -0.60170661 1.85227818 -0.01349722 -1.05771093 0.82254491 -1.22084365 0.2088636 -1.95967012 -1.32818605 0.19686124 0.73846658 0.17136828 -0.11564828 -0.3011037 -1.47852199 -0.71984421 -0.46063877 1.05712223 0.34361829 -1.76304016 0.32408397 -0.38508228 -0.676922 0.61167629 1.03099952 0.93128012 -0.83921752 -0.30921238 0.33126343 0.97554513 -0.47917424 -0.18565898 -1.10633497 -1.19620662 0.81252582 1.35624003 -0.07201012 1.0035329 0.36163603 -0.64511975 0.36139561 1.53803657 -0.03582604 1.56464366 -2.6197451 0.8219025 0.08704707 -0.29900735 0.09176078 -1.98756891 -0.21967189 0.35711257 1.47789404 -0.51827022 -0.8084936 -0.50175704 0.91540212 0.32875111 -0.5297602 0.51326743 0.09707755 0.96864499 -0.70205309 -0.32766215 -0.39210815 -1.46351495 0.29612028 0.26105527 0.00511346 -0.23458713]
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,355 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,163 Oct-12-2021, 02:16 PM
Last Post: player1682
  Random Particle Simulation in Blender willm168 3 2,813 Jul-13-2021, 10:54 AM
Last Post: Larz60+
  Can't make Random Forest Prediction work donnertrud 0 1,678 May-23-2020, 12:26 PM
Last Post: donnertrud
  Breaking a loop in Multiple Random Walks PythonGainz 10 4,286 May-01-2020, 03:15 PM
Last Post: buran
  Random Forest Hyperparamter Optimization donnertrud 1 1,987 Jan-17-2020, 06:30 AM
Last Post: scidam
  Random Forest high R2 Score but poor prediction donnertrud 5 5,200 Jan-13-2020, 11:23 PM
Last Post: jefsummers
  How to create a random library for an specific function andre_fermart 4 3,403 Apr-10-2019, 11:02 PM
Last Post: andre_fermart
  fill an empty matrix with random floats sofiapuvogel 2 3,324 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,737 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