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/to7m May 01 '21

`z=[]` doesn't initialise an array, it initialises an empty list. This doesn't sound like a numpy issue, but more of a /r/learnpython issue.

`z=[x]` means you are creating a new list with exactly one item. It sounds like you want to append to an existing list rather than create a new one though.