I’m trying to create a loop to check if a number in one array is 1 or 0, and then depending on this run some if statements using values from a different array which, depending on the if, will then append the original 1/0 array and run the loop again. the 1/0 array's first value has to be 1 so the code can work, and then add as it goes on, so the code would be adding to the array as it was running if that makes sense? like an excel spreadsheet uses the cell above in order to calculate a value as shown.
im very new to python and feel like there should be a very simple solution to this but i cant find one anywhere.
This is what im trying to do using python
My attempt
import random as rd
import numpy as np
import pandas as pd
pww = float(input("Pww Value: \n"))
pdd = float(input("Pdd Value: \n"))
pwd = float(1 - pww)
pdw = float(1 - pdd)
lda = float(input("Lambda Value:"))
random = np.random.rand(3649)
print(random)
state = np.array([1])
for x in state:
if x ==1:
for y in random:
if y < pww:
np.append(state, [1])
else:
np.append(state, [0])
if x == 0:
for y in random:
if y <pdd:
np.apend(state, [0])
else:
np.append(state, [1])
print(state)
any help is greatly appreciated.
i have looked at other posts which recommend enumerating the original array but that hasnt helped. other advice has been using the zip command but i dont really understand what that actually does - i couldnt get it to work anyway.