![]() |
NameError: name 'rand' is not defined - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: Data Science (https://python-forum.io/forum-44.html) +--- Thread: NameError: name 'rand' is not defined (/thread-27704.html) |
NameError: name 'rand' is not defined - Truman - Jun-17-2020 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) Any idea how to define this second .rand ?
RE: NameError: name 'rand' is not defined - buran - Jun-17-2020 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)
RE: NameError: name 'rand' is not defined - Truman - Jun-17-2020 Yeah, it makes sense although number 42 in parenthesis is still a mystery. RE: NameError: name 'rand' is not defined - buran - Jun-17-2020 Note, that is if you want the same seed 42 as in the example code RE: NameError: name 'rand' is not defined - buran - Jun-17-2020 (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 RE: NameError: name 'rand' is not defined - Truman - Jun-17-2020 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. Yeah, I'll have to ask my numerologist what 42 represents... RE: NameError: name 'rand' is not defined - buran - Jun-17-2020 (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.. RE: NameError: name 'rand' is not defined - Truman - Jun-17-2020 (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. ![]() |