Ok it´s late and i cannot solve the easiest problems anymore:
I have a Matrix with "zero-columns", these columns should be replaced with
a value from another array (same column index) that has the same number of columns:
a=np.array([[2,0,0,0],[1,0,2,0],[1,0,5,0]])
b=np.array([0.3,0.4,0.6,0.8])
result should be:
c=np.array([[2,0.4,0,0.8],[1,0.4,2,0.8],[1,0.4,5,0.8]])
i tried:
#searches for an entire zero-column indexes
wildcard_cols = np.nonzero(a.sum(axis=0) == 0)
i get:
out: wildcard_cols=array([[1, 3]], dtype=int64)# that is right
then i wanted to get a list from this output to iterate over the items in a list
wildcard_cols=np.asarray(wildcard_cols)
wildcard_cols=wildcard_cols.tolist()
but i get a list in a list(?) out=[[1, 3]]
so i cannot do:
for item in wildcard_cols:
a[:,item]=b[item]
#this does not work because i want to change every value in the column
i maybe thinking to complicated, but maybe someone finds a quick solution...
0.3
and0.8
? Wouldn't it be0.4
and0.8
if they're aligned? – DSM Dec 23 '13 at 2:42