python random number -


i wondering if can clarify line me.

create function die(x) rolls die x times keeping track of how many times each face comes , returns 1x6 array containing these numbers.

i not sure means when says 1x6 array ? using randint function numpy output array (or list) im not sure.

thanks

def die(x):     return np.bincount(np.random.random_integers(0, 5, size=x)) 

np.random.random_integers(0,5,size=x) rolls die x times (faces represented numbers 0 5 including).

np.bincount() returns number of occurrences of each value in array i.e., how many times each face comes up.

example

>>> = np.random.random_integers(0, 5, size=10) >>> array([3, 5, 0, 5, 0, 5, 5, 1, 3, 0]) >>> np.bincount(a) array([3, 1, 0, 2, 0, 4]) 

Comments

Popular posts from this blog

c# - How to set Z index when using WPF DrawingContext? -

razor - Is this a bug in WebMatrix PageData? -

visual c++ - Using relative values in array sorting ( asm ) -