Posts: 404
Threads: 94
Joined: Dec 2017
Jun-17-2020, 06:54 PM
(This post was last modified: Jun-17-2020, 06:54 PM by Truman.)
From the book...
We'll start by creating a random set of 10 points on a two-dimensional plane. Using the standard convention, we'll arrange these in a 10×2 array
import numpy as np
X = rand.rand(10, 2)
print(X) Error: ---------------------------------------------------------------------------
NameError Traceback (most recent call last)
<ipython-input-4-ac81983deccd> in <module>
1 import numpy as np
2 import random
----> 3 X = rand.rand(10, 2)
4 print(X)
NameError: name 'rand' is not defined
Any idea how to define this second .rand ?
Posts: 8,154
Threads: 160
Joined: Sep 2016
Jun-17-2020, 07:00 PM
(This post was last modified: Jun-17-2020, 07:00 PM by buran.)
In[9] rand = np.random.RandomState(42) so, your code would be
import numpy as np
rand = np.random.RandomState(42)
X = rand.rand(10, 2)
print(X) Output: [[0.37454012 0.95071431]
[0.73199394 0.59865848]
[0.15601864 0.15599452]
[0.05808361 0.86617615]
[0.60111501 0.70807258]
[0.02058449 0.96990985]
[0.83244264 0.21233911]
[0.18182497 0.18340451]
[0.30424224 0.52475643]
[0.43194502 0.29122914]]
Posts: 404
Threads: 94
Joined: Dec 2017
Yeah, it makes sense although number 42 in parenthesis is still a mystery.
Posts: 8,154
Threads: 160
Joined: Sep 2016
Note, that is if you want the same seed 42 as in the example code
Posts: 8,154
Threads: 160
Joined: Sep 2016
Jun-17-2020, 07:09 PM
(This post was last modified: Jun-17-2020, 07:11 PM by buran.)
(Jun-17-2020, 07:07 PM)Truman Wrote: number 42 in parenthesis is still a mystery. You know, 42 - The Answer to the Ultimate Question of Life, The Universe, and Everything.
I am sure they deliberately choose it as seed
Posts: 404
Threads: 94
Joined: Dec 2017
Jun-17-2020, 07:10 PM
(This post was last modified: Jun-17-2020, 07:11 PM by Truman.)
By the way, is there a chance that you also take a look at the topic " Computing the distance between each pair of points". These double colons are still making me headache.
(Jun-17-2020, 07:09 PM)buran Wrote: (Jun-17-2020, 07:07 PM)Truman Wrote: number 42 in parenthesis is still a mystery. You know, 42 - The Answer to the Ultimate Question of Life, The Universe, and Everything.
I am sure they deliberately choose it as seed
Yeah, I'll have to ask my numerologist what 42 represents...
Posts: 8,154
Threads: 160
Joined: Sep 2016
Jun-17-2020, 07:12 PM
(This post was last modified: Jun-17-2020, 07:12 PM by buran.)
(Jun-17-2020, 07:10 PM)Truman Wrote: Yeah, I'll have to ask my numerologist what 42 represents... (Jun-17-2020, 07:09 PM)buran Wrote: You know, 42 - The Answer to the Ultimate Question of Life, The Universe, and Everything..
Posts: 404
Threads: 94
Joined: Dec 2017
(Jun-17-2020, 07:12 PM)buran Wrote: (Jun-17-2020, 07:10 PM)Truman Wrote: Yeah, I'll have to ask my numerologist what 42 represents... (Jun-17-2020, 07:09 PM)buran Wrote: You know, 42 - The Answer to the Ultimate Question of Life, The Universe, and Everything..
The Hitchhiker's Guide to the Galaxy had some good parts and some not that good. Anyway, the author was an atheist so I don't think that I can get those answers that I need from him.
|