Python Forum
random interger array question
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
random interger array question
#1
I being ask to create a random integer array with the info below:

● Create two random integer array of values 0 to 14 of size ten called x and y.
Concatenate x and y using the concatenate method. Assign it to Q5.


my code is :
np.random.seed(56)
x = np.random.randint(15, size= (10))
y = np.random.randint(15, size= (10))

Q5 = np.concatenate([x,y])

print(Q5)
my print:
Output:
[ 5 4 0 2 11 10 14 9 11 7 6 4 9 10 7 1 8 12 2 14]
correct print is:
Output:
[ 5 3 2 5 1 5 1 11 14 10 4 3 9 7 6 7 7 14 0 4]
wondering why the answer print from my code doesnt match the correct answer code. I have assign seed of 56.
Yoriz write Nov-05-2022, 08:09 AM:
Please post all code, output and errors (in their entirety) between their respective tags. Refer to BBCode help topic on how to post. Use the "Preview Post" button to make sure the code is presented as you expect before hitting the "Post Reply/Thread" button.
Reply
#2
Why would you expect, when working with random numbers, to get exactly the same answer as something else?
Reply
#3
the answer suppose to be this :

Output:
[ 5 3 2 5 1 5 1 11 14 10 4 3 9 7 6 7 7 14 0 4]
which the question is asking me to spilt the random numbers

full question below:
● Create two random integer array of values 0 to 14 of size ten called x and y.
Concatenate x and y using the concatenate method. Assign it to Q5.
● Use the split method on Q5 to create each of the following:
Q6a: [5 3 2 5]
Q6b: [ 1 5 1 11 14 10 4]
Q6c: [3 9 7 6 7 7]
Q6d: [14 0 4]

but my code:
np.random.seed(56)
x = np.random.randint(15, size= (10))
y = np.random.randint(15, size= (10))

Q5 = np.concatenate([x,y])

print(Q5)
my print which is wrong:

Output:
[ 5 4 0 2 11 10 14 9 11 7 6 4 9 10 7 1 8 12 2 14]
generate a numbers which doesn't match the question print answer:

Output:
[ 5 3 2 5 1 5 1 11 14 10 4 3 9 7 6 7 7 14 0 4]
______________________________________________________________________________________________________________________________
but if I run a code:
np.random.seed(56)
x = np.random.randint(15, size= (10,10))
y = np.random.randint(15, size= (10,10))

Q5 = np.concatenate([x,y])

print(Q5)
with the 10,10 i can see the correct numbers are listed on line 16.
Output:
[[ 5 4 0 2 11 10 14 9 11 7] [ 6 4 9 10 7 1 8 12 2 14] [11 11 14 0 5 6 1 9 10 12] [ 5 5 2 12 9 3 5 9 2 10] [ 1 0 13 4 6 2 12 0 8 13] [ 6 14 4 14 0 14 1 11 1 13] [12 3 14 14 9 6 13 10 2 1] [ 3 8 8 3 2 0 3 0 5 8] [ 0 8 6 12 10 13 0 9 4 11] [10 14 13 6 0 10 2 3 7 1] [11 11 6 5 0 11 12 6 8 2] [13 8 7 12 6 0 3 4 2 7] [ 2 4 5 0 14 7 10 1 1 8] [ 6 7 4 13 1 7 8 13 4 11] [ 3 6 2 10 5 0 8 0 5 3] [ 7 8 7 0 10 10 9 11 1 3] [ 5 3 2 5 1 5 1 11 14 10] [ 4 3 9 7 6 7 7 14 0 4] [14 8 9 0 1 11 1 3 6 7] [ 7 5 2 6 0 12 7 13 11 7]]
wondering what is wrong with my code?

thank you in advance i am quite new to python.
Yoriz write Nov-05-2022, 08:42 AM:
Please post all code, output and errors (in their entirety) between their respective tags. Refer to BBCode help topic on how to post. Use the "Preview Post" button to make sure the code is presented as you expect before hitting the "Post Reply/Thread" button.
Reply
#4
I get your results. Are you sure about the seed value?
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  How to Generate and Print An Array with Random Numbers in Python in the johnnynitro99293 14 9,667 Sep-20-2019, 11:56 AM
Last Post: ichabod801

Forum Jump:

User Panel Messages

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