python - NumPy: create bool array like "repeat" but in multiple dimensions -
I look for the opposite type of So I want to go opposite direction In an array like: The solution works ideally for high dimensions, and I definitely do not want to loop in Python, because input can be longer than this example. He said, here is a solution using a loop: IIUC - and I'm not sure that I do - you can compare or in 2D: sum () We go here:
x = array ([[false, false, false, false, false], [true, false, false, false, false] [true, false, false, false], [ True, true, false, false]] x.sum (axis = 1) outside: array ([0, 1, 2, 3])
[0,1,2,3] to
s = np.array ([0, 1, 2, 3]) y = np.zeros ((lane, 5) , Np.bool) for the line, call in the calculation (s): y [row, 0: col] = true
notation and a broadcast:
& Gt; & Gt; & Gt; V = np.array ([0,1,3,2]) & gt; & Gt; & Gt; NP Dyed (5) & lt; V [..., none] Array ([[false, false, false, false, false], [true, false, false, false, false] [This is true, true, false, false] true , Right, wrong, wrong, wrong]], dtype = bool
> gt;>> V = Np.array ([[1,2], [0,2]])>>> NP Dyed (5)
Comments
Post a Comment