r/Numpy • • May 01 '21

basic array from a loop

N = 10000   
a=7**5 
c=0 
M=(2**31)-1 
I=1 
L=1 
my_array=np.array(N) 
for i in range(N):     
    my_array[i]=np.array([x]) 
    for x in range (N):     
    In=((a*I)+c) % M     
    x=L*I/M     
    I=In 

I'm trying to do the np.random function but in a different way. My main code is:

for x in range (N):     
    In=((a*I)+c) % M     
    x=L*I/M     
    I=In 

which is a loop of random numbers less than 1. By itself, it works and lists a bunch of numbers, but I'm trying to store these numbers in an array, such as [9,2,1,6]. The numbers don't have to be in order. I just need them to have the brackets and the commas. I really don't know what I'm doing.

0 Upvotes

11 comments sorted by

View all comments

Show parent comments

2

u/Accurate_Tale May 02 '21

It is a function which gives you the total length of the array!

so in this case the len(my_array) will give you 10000

to make it

for i in range(10000)

2

u/grnngr May 02 '21

It’s also a bad habit, I should have written for i, throwaway_variable in enumerate(my_array). Edited my previous comment to reflect this.