Please help on how I could use a.any() or a.all() in such a case, as my attempt np.all(x[i] == 0 and x[j] == 0) == True and True
makes no difference.
def count(x):
""" similar to q table, if 0 and 0 in consecutive ,then 0.3 is appended in the count_set...."""
count_set = []
for i in range(x.shape[0]):
for j in range(x.shape[1]):
if x[i] == 0 and x[j] == 0:
count_set.append(0.3)
elif x[i] == 0 and x[j] ==1 or x[i] == 1 and x[j] ==0 :
count_set = append(0.1)
else :
count_set.append(0.5)
return np.cumsum(count_set)
input_sample = np.array([[1,0,1,0],[1,1,0,0]])
count(input_sample)
Solution should be calculated as follows 1 and 0 is consecutive twice hence 0.1 is append, as from the 2nd if statement.
1 and 1 is obeys the third if else statement hence 1 and 1 is appended.
Finally, the last two 0s are consecutive , as from the 1st if statement means 0.3 is appended. count_set =[0.1,0.1,1,1,0.3] np.cumsum(count_set ) = 2.5