C
Carl
I have the following matrix that I want to transform:
import random
import Numeric as N
ru = []
for i in range(25):
ru.append(int(random.uniform(0, 2)))
ru = N.reshape(ru, (5, 5))
array([[1, 0, 1, 1, 1],
[0, 1, 1, 1, 0],
[1, 1, 0, 0, 1],
[0, 1, 0, 0, 1],
[1, 1, 0, 1, 1]])
Trailing numbers (ie, from left to right) after the first encounter of a "1"
for all rows should equal "0".
Thus, I want this:
array([[1, 0, 0, 0, 0],
[0, 1, 0, 0, 0],
[1, 0, 0, 0, 0],
[0, 1, 0, 0, 0],
[1, 0, 0, 0, 0]])
Does anyone have a suggestion of a fast and easy way to accomplish the
above?
Carl
import random
import Numeric as N
ru = []
for i in range(25):
ru.append(int(random.uniform(0, 2)))
ru = N.reshape(ru, (5, 5))
array([[1, 0, 1, 1, 1],
[0, 1, 1, 1, 0],
[1, 1, 0, 0, 1],
[0, 1, 0, 0, 1],
[1, 1, 0, 1, 1]])
Trailing numbers (ie, from left to right) after the first encounter of a "1"
for all rows should equal "0".
Thus, I want this:
array([[1, 0, 0, 0, 0],
[0, 1, 0, 0, 0],
[1, 0, 0, 0, 0],
[0, 1, 0, 0, 0],
[1, 0, 0, 0, 0]])
Does anyone have a suggestion of a fast and easy way to accomplish the
above?
Carl