Python Forum
random interger array question - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: Homework (https://python-forum.io/forum-9.html)
+--- Thread: random interger array question (/thread-38613.html)



random interger array question - rpang - Nov-05-2022

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.


RE: random interger array question - ndc85430 - Nov-05-2022

Why would you expect, when working with random numbers, to get exactly the same answer as something else?


RE: random interger array question - rpang - Nov-05-2022

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.


RE: random interger array question - deanhystad - Nov-05-2022

I get your results. Are you sure about the seed value?