python - NumPy: create bool array like "repeat" but in multiple dimensions -


I look for the opposite type of 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])   

So I want to go opposite direction In an array like: [0,1,2,3] to x (I can specify the number of columns X, of course, above 5).

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:

  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    

IIUC - and I'm not sure that I do - you can compare 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   

or in 2D:

 > gt;>> V = Np.array ([[1,2], [0,2]])>>> NP Dyed (5)  V [..., any] array ([[ [True, false, false, false, false] [true, false, false, false]], [[false, false, false, false, false] [tru, false, false, false, false]]] , DTP = bull)> gt; & gt; ((Np.arange (5)    

Comments

Popular posts from this blog

java - ImportError: No module named py4j.java_gateway -

python - Receiving "KeyError" after decoding json result from url -

.net - Creating a new Queue Manager and Queue in Websphere MQ (using C#) -