Assuming that there are 3 columns and there's 1 or none negative value in each remaining column that are being replaced by the average of the entire column.
Then:
np = [[5],[3],[1.0,2.0,10.0],[-1.0,-99.0,0],[-1.0,4.0,0],[3.0,-6.0,-0.1],[1.0,-0.31, 6.0]]
cols = 0 # save num of cols for later
for l in inp:
pos = 0 # count positive
neg = 0 # count negative
for n in l:
if n > 0:
pos += 1 # update
elif n < 0:
neg += 1 # update
if pos+neg > cols: # save num of cols
cols = pos+neg
if pos < neg: # remove list with too many negatives
inp.remove(l)
for i in range(cols): # loop through cols
neg_index = 0 # find the negative value's index to replace with the average
entries = 0 # for calculating the average
summ = 0 # for calculating the average
for c in inp:
try: # see if col exist in a list
if c[i] < 0:
neg_index = inp.index(c) # save index of negative value found
else:
summ += c[i]
entries += 1
except:
continue
try: # see if col exist in list
inp[neg_index][i] = round(summ / entries,1) # replace negative value index with average
except:
continue
print(inp)
Result:
[5],
[3],
[1.0, 2.0, 10.0],
[2.5, 4.0, 0],
[1.0, 3.0, 6.0],
I believe this is what they were looking for, hope this helps.