I have an array of probabilities. I would like the columns to sum to 1 (representing probability) and the rows to sum to X (where X is an integer, say 9 for example). 

I thought that I could normalize the columns, and then normalize the rows and times by X. But this didn't work, the resulting sums of the rows and columns were not perfectly 1.0 and X. 

This is what I tried:

```
# B is 5 rows by 30 columns

# Normalizing columns to 1.0
col_sum = []
for col in B.T:
    col_sum.append(sum(col))

for row in range(B.shape[0]): 
    for col in range(B.shape[1]):
        if B[row][col] != 0.0 and B[row][col] != 1.0:
            B[row][col] = (B[row][col] / col_sum[col])

# Normalizing rows to X (9.0)
row_sum = []
for row in B:
    row_sum.append(sum(row))

for row in range(B.shape[0]): 
    for col in range(B.shape[1]):
        if B[row][col] != 0.0 and B[row][col] != 1.0:
            B[row][col] = (B[row][col] / row_sum[row]) * 9.0

```